本文整理汇总了C#中KeyModifiers.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# KeyModifiers.HasFlag方法的具体用法?C# KeyModifiers.HasFlag怎么用?C# KeyModifiers.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyModifiers
的用法示例。
在下文中一共展示了KeyModifiers.HasFlag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFunctionKeyModifier
/// <summary>
/// Gets an ANSI function key modifier string representing the pressed <see cref="KeyModifiers"/>.
/// </summary>
/// <param name="keyModifiers">The pressed key modifiers.</param>
/// <returns>The ANSI function key modifier string.</returns>
private static string GetFunctionKeyModifier(KeyModifiers keyModifiers)
{
// This method is disabled at the moment...
return string.Empty;
bool isShiftKeyDown = keyModifiers.HasFlag(KeyModifiers.Shift);
bool isAltKeyDown = keyModifiers.HasFlag(KeyModifiers.Alt);
bool isControlKeyDown = keyModifiers.HasFlag(KeyModifiers.Ctrl);
if (isShiftKeyDown && !isAltKeyDown && !isControlKeyDown)
{
return ";2";
}
else if (!isShiftKeyDown && isAltKeyDown && !isControlKeyDown)
{
return ";3";
}
else if (isShiftKeyDown && isAltKeyDown && !isControlKeyDown)
{
return ";4";
}
else if (!isShiftKeyDown && !isAltKeyDown && isControlKeyDown)
{
return ";5";
}
else if (isShiftKeyDown && !isAltKeyDown && isControlKeyDown)
{
return ";6";
}
else if (!isShiftKeyDown && isAltKeyDown && isControlKeyDown)
{
return ";7";
}
else if (isShiftKeyDown && isAltKeyDown && isControlKeyDown)
{
return ";8";
}
return string.Empty;
}
示例2: ProcessUserInput
/// <summary>
/// Processes user input in a way that is specific to the terminal implementation.
/// </summary>
/// <param name="key">The input key.</param>
/// <param name="keyModifiers">The key modifiers.</param>
/// <returns>A value indicating whether the key press was processed by the terminal implementation.</returns>
/// <remarks>
/// This method receives key presses of non-character keys (e.g. Up, Down, Left, Right, Function keys F1-F12, Alt/Ctrl key combinations, ...).
/// </remarks>
protected override bool ProcessUserInput(VirtualKey key, KeyModifiers keyModifiers)
{
string input;
// handle Alt key combinations
if (keyModifiers.HasFlag(KeyModifiers.Alt))
{
if (key >= VirtualKey.Number0 && key <= VirtualKey.Number9)
{
input = "\x1b" + (char)key;
}
else if (key >= VirtualKey.A && key <= VirtualKey.Z)
{
// the "+ 32" produces lower case characters
input = "\x1b" + (char)(key + (keyModifiers.HasFlag(KeyModifiers.Shift) ? 0 : 32));
}
else if (key == VirtualKey.Shift || key == VirtualKey.Menu || key == VirtualKey.Control)
{
return false;
}
else
{
return false;
}
}
else if (keyModifiers == KeyModifiers.Ctrl)
{
if (key == VirtualKey.Space)
{
this.ignoreStringUserInput = true;
input = "\0";
}
else if (key == VirtualKey.Shift || key == VirtualKey.Menu || key == VirtualKey.Control)
{
return false;
}
else if (key == (VirtualKey)191) // Ctrl + / (US keyboard)
{
input = "\x1f";
}
else
{
return false;
}
}
else
{
switch (key)
{
case VirtualKey.Back:
this.ignoreStringUserInput = true;
input = "\x7f";
break;
case VirtualKey.Enter:
input = Environment.NewLine;
break;
case VirtualKey.Tab:
input = "\t";
break;
case VirtualKey.Left:
input = this.applicationCursorKeys ? "\u001bOD" : "\u001b[D";
break;
case VirtualKey.Up:
input = this.applicationCursorKeys ? "\u001bOA" : "\u001b[A";
break;
case VirtualKey.Right:
input = this.applicationCursorKeys ? "\u001bOC" : "\u001b[C";
break;
case VirtualKey.Down:
input = this.applicationCursorKeys ? "\u001bOB" : "\u001b[B";
break;
case VirtualKey.Insert:
input = "\u001b[2~";
break;
case VirtualKey.Delete:
input = "\u001b[3~";
break;
case VirtualKey.Home:
input = "\u001b[1~";
break;
case VirtualKey.End:
input = "\u001b[4~";
break;
case VirtualKey.PageUp:
input = "\u001b[5~";
break;
case VirtualKey.PageDown:
input = "\u001b[6~";
break;
case VirtualKey.F1:
input = "\u001b[11" + GetFunctionKeyModifier(keyModifiers) + "~";
//.........这里部分代码省略.........