本文整理汇总了C#中Keys.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# Keys.HasFlag方法的具体用法?C# Keys.HasFlag怎么用?C# Keys.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Keys
的用法示例。
在下文中一共展示了Keys.HasFlag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessCmdKey
protected override bool ProcessCmdKey(ref Message m, Keys keyData)
{
if (keyData.HasFlag(Keys.Escape)) { RemoveIt(); return true; }
if (keyData.HasFlag(Keys.Enter)) {
Parent.GoToLine(TextBox.Text);
RemoveIt();
}
return base.ProcessCmdKey(ref m, keyData);
}
示例2: ConvertModifier
public static swi.ModifierKeys ConvertModifier (Keys key)
{
key &= Keys.ModifierMask;
swi.ModifierKeys val = swi.ModifierKeys.None;
if (key.HasFlag (Keys.Alt)) val |= swi.ModifierKeys.Alt;
if (key.HasFlag (Keys.Control)) val |= swi.ModifierKeys.Control;
if (key.HasFlag (Keys.Shift)) val |= swi.ModifierKeys.Shift;
if (key.HasFlag (Keys.Application)) val |= swi.ModifierKeys.Windows;
return val;
}
示例3: KeysToModifierKeys
/// <summary>
/// Translate Keys to ModifierKeys standard for GlobalHotkeys
/// </summary>
/// <param name="keys">Keys as ModifierKeys</param>
/// <returns>ModifierKeys</returns>
public static ModifierKeys KeysToModifierKeys(Keys keys)
{
var mfk = new ModifierKeys();
if (keys.HasFlag(Keys.Shift))
mfk |= ModifierKeys.Shift;
if (keys.HasFlag(Keys.Control))
mfk |= ModifierKeys.Control;
if (keys.HasFlag(Keys.LWin | Keys.RWin))
mfk |= ModifierKeys.Win;
if (keys.HasFlag(Keys.Alt))
mfk |= ModifierKeys.Alt;
return mfk;
}
示例4: ProcessCmdKey
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData.HasFlag(Keys.Control))
{
if (keyData.HasFlag(Keys.O))
{
OpenMenuItem.PerformClick();
return true;
}
if (keyData.HasFlag(Keys.Alt) && keyData.HasFlag(Keys.Shift) && keyData.HasFlag(Keys.S))
{
SaveDecryptedMenuItem.PerformClick();
return true;
}
if (keyData.HasFlag(Keys.Shift) && keyData.HasFlag(Keys.S))
{
SaveEncryptedMenuItem.PerformClick();
return true;
}
if (keyData.HasFlag(Keys.S))
{
SaveMenuItem.PerformClick();
return true;
}
}
return m_tabPages.Any(tabPage => tabPage.OnHotkey(keyData)) || base.ProcessCmdKey(ref msg, keyData);
}
示例5: KeyEquivalentModifierMask
public static NSEventModifierMask KeyEquivalentModifierMask (Keys key)
{
key &= Keys.ModifierMask;
var mask = (NSEventModifierMask)0;
if (key.HasFlag(Keys.Shift))
mask |= NSEventModifierMask.ShiftKeyMask;
if (key.HasFlag(Keys.Alt))
mask |= NSEventModifierMask.AlternateKeyMask;
if (key.HasFlag(Keys.Control))
mask |= NSEventModifierMask.ControlKeyMask;
if (key.HasFlag(Keys.Application))
mask |= NSEventModifierMask.CommandKeyMask;
return mask;
}
示例6: GetFlags
private static HotkeyFlags GetFlags(Keys hotkey, bool noRepeat)
{
var noMod = hotkey & ~Keys.Modifiers;
var flags = HotkeyFlags.None;
if (hotkey.HasFlag(Keys.Alt))
flags |= HotkeyFlags.Alt;
if (hotkey.HasFlag(Keys.Control))
flags |= HotkeyFlags.Control;
if (hotkey.HasFlag(Keys.Shift))
flags |= HotkeyFlags.Shift;
if (noMod == Keys.LWin || noMod == Keys.RWin)
flags |= HotkeyFlags.Windows;
if (noRepeat)
flags |= HotkeyFlags.NoRepeat;
return flags;
}
示例7: AssertAKeyPress
private void AssertAKeyPress(Keys key)
{
int neededInputs = 2;
var modifiers = new Keys?[3];
if (key.HasFlag(Keys.Shift))
{
modifiers[0] = Keys.ShiftKey;
neededInputs += 2;
}
if (key.HasFlag(Keys.Control))
{
modifiers[1] = Keys.ControlKey;
neededInputs += 2;
}
if (key.HasFlag(Keys.Alt))
{
modifiers[2] = Keys.Menu;
neededInputs += 2;
}
Assert.AreEqual(neededInputs, _inputs.Count);
int currentInput = 0;
foreach (var modifier in modifiers)
{
if (modifier.HasValue)
{
AssertIsKeyDownInputFor(modifier.Value, _inputs[currentInput++]);
}
}
AssertIsKeyDownInputFor(key, _inputs[currentInput++]);
AssertIsKeyUpInputFor(key, _inputs[currentInput++]);
foreach (var modifier in modifiers)
{
if (modifier.HasValue)
{
AssertIsKeyUpInputFor(modifier.Value, _inputs[currentInput++]);
}
}
}
示例8: ProcessCmdKey
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (waitLabel != null)
{
if (!keyData.HasFlag(Keys.Control) && !keyData.HasFlag(Keys.Alt) && !keyData.HasFlag(Keys.Shift))
{
switch (waitKey)
{
case GameInput.Up: GameInputKeys.Up = keyData; break;
case GameInput.Down: GameInputKeys.Down = keyData; break;
case GameInput.Left: GameInputKeys.Left = keyData; break;
case GameInput.Right: GameInputKeys.Right = keyData; break;
case GameInput.Jump: GameInputKeys.Jump = keyData; break;
case GameInput.Shoot: GameInputKeys.Shoot = keyData; break;
case GameInput.Start: GameInputKeys.Start = keyData; break;
case GameInput.Select: GameInputKeys.Select = keyData; break;
}
waitLabel.Text = keyData.ToString();
waitLabel = null;
return true; // Needs to be here, so if a key picked like up, selected button must not be changed.
}
else
{
string key = "";
if (keyData.HasFlag(Keys.Control)) key = "ctrl";
else if (keyData.HasFlag(Keys.Alt)) key = "Alt";
else if (keyData.HasFlag(Keys.Shift)) key = "Shift";
MessageBox.Show(this, "Key " + key + " is not allowed.", "Unhauthorized key", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
示例9: ModifierExtractor
public ModifierExtractor(Keys modifiedKey)
{
_shift = modifiedKey.HasFlag(Keys.Shift);
_ctrl = modifiedKey.HasFlag(Keys.Control);
_alt = modifiedKey.HasFlag(Keys.Alt);
}
示例10: ProcessKeyDown
internal bool ProcessKeyDown(Keys pKeys)
{
if(pKeys == (Keys.Control | Keys.X))
m_session.Gui_ClearSelectedLayer();
else if(pKeys == (Keys.Control | Keys.Z))
m_session.Gui_Undo();
else if (pKeys.HasFlag(Keys.Shift))
m_zoomTool.Enabled = true;
else if (pKeys.HasFlag(Keys.Alt))
m_panTool.Enabled = true;
else if (pKeys.HasFlag(Keys.Oemplus))
SetZoom(m_magnification * 1.5f, true);
else if (pKeys.HasFlag(Keys.OemMinus))
SetZoom(m_magnification / 1.5f, true);
else
return false;
return true;
}
示例11: SetHotkeyText
public static void SetHotkeyText(Keys keyData)
{
if (keyData.HasFlag(Alt))
{
HotkeyText = "Alt";
return;
}
var converter = new KeysConverter();
string keyText = converter.ConvertToString(keyData);
// show the [ ] ~ etc keys instead of Oem<whatever>
if (keyText.StartsWith("Oem", StringComparison.Ordinal))
{
uint nonVirtualKey = MapVirtualKey((uint)keyData, 2) & 0x7fffffff;
char mappedChar = Convert.ToChar(nonVirtualKey);
HotkeyText = mappedChar == '\0' ? keyText : mappedChar.ToString();
}
else
{
HotkeyText = keyText;
}
}
示例12: KeyEventMatcher
public KeyEventMatcher(Keys key)
{
_shift = key.HasFlag(Keys.Shift);
_control = key.HasFlag(Keys.Control);
_alt = key.HasFlag(Keys.Alt);
_keyCode = key & Keys.KeyCode;
}
示例13: ProcessCmdKey
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData.HasFlag(Keys.Up) || keyData.HasFlag(Keys.Down) || keyData.HasFlag(Keys.Left) || keyData.HasFlag(Keys.Right) || keyData.HasFlag(Keys.Tab))
{
KeyEventArgs args = new KeyEventArgs(keyData);
args.Handled = false;
this.OnKeyDown(args);
if (args.Handled) return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
示例14: HasPressed
/// <summary>
/// Checks if <see cref="Keys" /> have been pressed.
/// </summary>
/// <param name="newKeys">New <see cref="Keys" />.</param>
/// <param name="oldKeys">Old <see cref="Keys" />.</param>
/// <param name="keys">The <see cref="Keys" /> to check for.</param>
/// <returns>Whether the <see cref="Keys" /> have been pressed.</returns>
public static bool HasPressed(Keys newKeys, Keys oldKeys, Keys keys)
{
return newKeys.HasFlag(keys) && !oldKeys.HasFlag(keys);
}
示例15: ToStringWithModifiers
/// <summary>
/// Gives a formatted version of the key listing all active
/// modifiers, the key name and the likely value for the key.
/// </summary>
///
public string ToStringWithModifiers(Keys key)
{
StringBuilder builder = new StringBuilder(100);
bool shift = key.HasFlag(Keys.Shift);
bool alt = key.HasFlag(Keys.Alt);
bool ctrl = key.HasFlag(Keys.Control);
bool win = key.HasFlag(KeysExtensions.Windows);
key = key.RemoveModifiers();
if (shift)
{
builder.Append("Shift");
}
if (ctrl)
{
if (builder.Length > 0)
builder.Append(" + ");
builder.Append("Control");
}
if (alt)
{
if (builder.Length > 0)
builder.Append(" + ");
builder.Append("Alt");
}
if (win)
{
if (builder.Length > 0)
builder.Append(" + ");
builder.Append("Win");
}
if (key != Keys.None)
{
if (builder.Length > 0)
builder.Append(" + ");
string raw = ToKeyNameString(key);
if (raw == null)
return builder.ToString();
string mod = ToUnicodeCharString(key, shift, alt);
builder.Append(raw);
if (raw != mod && !String.IsNullOrWhiteSpace(mod))
builder.AppendFormat(" ({0})", mod);
}
return builder.ToString();
}