本文整理汇总了C#中MediaPortal.UI.Control.InputManager.Key类的典型用法代码示例。如果您正苦于以下问题:C# Key类的具体用法?C# Key怎么用?C# Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Key类属于MediaPortal.UI.Control.InputManager命名空间,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeKey
protected static string SerializeKey(Key key)
{
if (key.IsPrintableKey)
return "P:" + key.RawCode;
else if (key.IsSpecialKey)
return "S:" + key.Name;
else
throw new NotImplementedException(string.Format("Cannot serialize key '{0}', it is neither a printable nor a special key", key));
}
示例2: OnKeyPreview
public override void OnKeyPreview(ref Key key)
{
base.OnKeyPreview(ref key);
if (!HasFocus)
return;
// We handle "normal" button presses in the KeyPreview event, because the "Default" event needs
// to be handled after the focused button was able to consume the event
if (key == Key.None) return;
if (key == Key.Ok)
{
Execute();
key = Key.None;
}
}
示例3: RegisterKeyBinding
protected void RegisterKeyBinding()
{
if (_registeredScreen != null)
return;
if (Key == null)
return;
Screen screen = Screen;
if (screen == null)
return;
_registeredScreen = screen;
_registeredKey = Key;
_registeredScreen.AddKeyBinding(_registeredKey, new KeyActionDlgt(Execute));
}
示例4: AvoidDuplicateKeys
protected void AvoidDuplicateKeys(Key key)
{
if (_workflowActionShortcuts.ContainsKey(key))
throw new ArgumentException(string.Format("A global shortcut for Key '{0}' was already registered with action '{1}'", key, _workflowActionShortcuts[key].Name));
if (_workflowStateShortcuts.ContainsKey(key))
throw new ArgumentException(string.Format("A global shortcut for Key '{0}' was already registered with state '{1}'", key, _workflowStateShortcuts[key].Name));
}
示例5: ConvertType
//.........这里部分代码省略.........
{
t = new Thickness(numberList[0], numberList[1]);
}
else if (numberList.Length == 4)
{
t = new Thickness(numberList[0], numberList[1], numberList[2], numberList[3]);
}
else
{
throw new ArgumentException("Invalid # of parameters");
}
result = t;
return true;
}
else if (targetType == typeof(Color))
{
Color color;
if (ColorConverter.ConvertColor(value, out color))
{
result = color;
return true;
}
}
else if (targetType == typeof(Brush) && value is string || value is Color)
{
try
{
Color color;
if (ColorConverter.ConvertColor(value, out color))
{
SolidColorBrush b = new SolidColorBrush
{
Color = color
};
result = b;
return true;
}
}
catch (Exception)
{
return false;
}
}
else if (targetType == typeof(GridLength))
{
string text = value.ToString();
if (text == "Auto")
result = new GridLength(GridUnitType.Auto, 0.0);
else if (text == "AutoStretch")
result = new GridLength(GridUnitType.AutoStretch, 1.0);
else if (text.IndexOf('*') >= 0)
{
int pos = text.IndexOf('*');
text = text.Substring(0, pos);
if (text.Length > 0)
{
object obj;
TypeConverter.Convert(text, typeof(double), out obj);
result = new GridLength(GridUnitType.Star, (double)obj);
}
else
result = new GridLength(GridUnitType.Star, 1.0);
}
else
{
double v = double.Parse(text);
result = new GridLength(GridUnitType.Pixel, v);
}
return true;
}
else if (targetType == typeof(string) && value is IResourceString)
{
result = ((IResourceString)value).Evaluate();
return true;
}
else if (targetType.IsAssignableFrom(typeof(IExecutableCommand)) && value is ICommand)
{
result = new CommandBridge((ICommand)value);
return true;
}
else if (targetType == typeof(Key) && value is string)
{
string str = (string)value;
// Try a special key
result = Key.GetSpecialKeyByName(str);
if (result == null)
if (str.Length != 1)
throw new ArgumentException(string.Format("Cannot convert '{0}' to type Key", str));
else
result = new Key(str[0]);
return true;
}
else if (targetType == typeof(string) && value is IEnumerable)
{
result = StringUtils.Join(", ", (IEnumerable)value);
return true;
}
result = value;
return false;
}
示例6: HandleClipboardKeys
protected void HandleClipboardKeys(ref Key key)
{
if (!HasFocus)
return;
if (key == Key.Cut)
{
if (ServiceRegistration.Get<IClipboardManager>().SetClipboardText(Text))
{
Text = string.Empty;
key = Key.None;
}
}
else if (key == Key.Copy)
{
if (ServiceRegistration.Get<IClipboardManager>().SetClipboardText(Text))
key = Key.None;
}
else if (key == Key.Paste)
{
string text;
if (ServiceRegistration.Get<IClipboardManager>().GetClipboardText(out text))
{
// If caret is placed on end, simply append the text
if (CaretIndex == Text.Length)
Text += text;
else
{
string beforeCaret = Text.Substring(0, CaretIndex);
string afterCaret = Text.Substring(CaretIndex);
Text = string.Format("{0}{1}{2}", beforeCaret, text, afterCaret);
CaretIndex = beforeCaret.Length + text.Length;
}
key = Key.None;
}
}
}
示例7: OnKeyPressed
/// <summary>
/// Will be called when a key is pressed. Derived classes may override this method
/// to implement special key handling code.
/// </summary>
/// <param name="key">The key. Should be set to 'Key.None' if handled by child.</param>
public virtual void OnKeyPressed(ref Key key)
{
foreach (UIElement child in GetChildren())
{
if (!child.IsVisible) continue;
child.OnKeyPressed(ref key);
if (key == Key.None) return;
}
}
示例8: MappedKeyCode
public MappedKeyCode(Key key, string code)
{
_key = key;
_code = code;
}
示例9: SerializeKey
/// <summary>
/// Serializes a <see cref="Key"/> into a string. This method supports both printable and special keys.
/// </summary>
/// <param name="key">Key</param>
/// <returns>Key string.</returns>
/// <exception cref="ArgumentException">If key is neither printable nor special key.</exception>
public static string SerializeKey(Key key)
{
if (key.IsPrintableKey)
return "P:" + key.RawCode;
if (key.IsSpecialKey)
return "S:" + key.Name;
throw new ArgumentException(string.Format("Cannot serialize key '{0}', it is neither a printable nor a special key", key));
}
示例10: KeyEventArgs
/// <summary>
/// Creates a new instance of <see cref="KeyboardEventArgs"/>.
/// </summary>
/// <param name="timestamp">Time when the input occurred.</param>
/// <param name="key">Key to associate with this event.</param>
public KeyEventArgs( /*KeyboardDevice keyboard,*/ int timestamp, Key key)
: base( /*keyboard,*/ timestamp)
{
_key = key;
}
示例11: HandleInput
public abstract void HandleInput(ref Key key);
示例12: MappedKeyCode
public MappedKeyCode(Key key, int code)
{
Key = key;
Code = code;
}
示例13: OnKeyPressed
public override void OnKeyPressed(ref Key key)
{
base.OnKeyPressed(ref key);
if (!IsActive || key == Key.None)
return;
ICommandStencil command = KeyPressedCommand;
if (command == null)
return;
command.Execute(new object[] {key});
}
示例14: OnKeyPressed
public override void OnKeyPressed(ref Key key)
{
base.OnKeyPressed(ref key);
if (key == Key.None)
// Key event was handeled by child
return;
int updatedStartsWithIndex = -1;
try
{
if (!CheckFocusInScope())
return;
if (key.IsPrintableKey)
{
if (_startsWithIndex == -1 || _startsWith != key.RawCode)
{
_startsWith = key.RawCode.Value;
updatedStartsWithIndex = 0;
}
else
updatedStartsWithIndex = _startsWithIndex + 1;
key = Key.None;
if (!FocusItemWhichStartsWith(_startsWith, updatedStartsWithIndex))
updatedStartsWithIndex = -1;
}
}
finally
{
// Will reset the startsWith function if no char was pressed
_startsWithIndex = updatedStartsWithIndex;
}
}
示例15: OnKeyPressed
public override void OnKeyPressed(ref Key key)
{
// We handle the "Default" event here, "normal" events will be handled in the KeyPreview event
base.OnKeyPressed(ref key);
if (key == Key.None) return;
if (IsDefault && key == Key.Ok)
{
Execute();
key = Key.None;
}
}