本文整理汇总了C#中System.Windows.Forms.KeyEventArgs.Key方法的典型用法代码示例。如果您正苦于以下问题:C# KeyEventArgs.Key方法的具体用法?C# KeyEventArgs.Key怎么用?C# KeyEventArgs.Key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.KeyEventArgs
的用法示例。
在下文中一共展示了KeyEventArgs.Key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HookManager_KeyDown
public void HookManager_KeyDown(object sender, KeyEventArgs e)
{
//Log(string.Format("{0}", e.KeyValue));
try
{
if (Skip)
{
if (DoLog) Log("Skip Down " + e.Key().ToString());
return;
}
if (PressedKeys.Count > 0)
{
var Chord = PressedKeys.Aggregate("", (s, key) => s + key.Value + ',');
if (DoLog) Log(string.Format("Chord is {0} {1}. {2} keys total.", Chord, e.Key().Value, PressedKeys.Count + 1));
}
// Shift-Shift = CapsLock
if (CheckForShiftShift(e)) return;
// Log event info
if (DoLog) Log(string.Format("Window name is {0}", WindowFunctions.GetActiveWindowTitle()));
if (DoLog) Log(string.Format("KeyDown {0} ({1}) {2}{3}{4}", e.KeyCode, (char)e.KeyValue,
Key.Shift.IsDown ? " Shift" : "",
Key.Alt.IsDown ? " Alt" : "",
Key.Ctrl.IsDown ? " Ctrl" : ""));
if (e.KeyCode == Keys.B)
Console.Write("");
KeyMap CurrentMap = null;
if (HoldContext == null)
{
Ambiguous = false;
HoldContext = Base.ActiveContext;
CurrentMap = Base.ActiveContextMap;
Base.CurrentContext = HoldContext;
}
else
{
if (DoLog) Log(string.Format("CurrentContext is {0}", HoldContext));
CurrentMap = Base.GetContextMap(HoldContext);
foreach (var k in PressedKeys)
{
if (CurrentMap == null) break;
if (CurrentMap.ContainsKey(k))
{
var result = CurrentMap[k];
if (result.MyMap != null)
{
CurrentMap = result.MyMap;
}
else
{
CurrentMap = null;
break;
}
}
else
{
CurrentMap = null;
break;
}
}
}
if (CurrentMap != null && CurrentMap.ContainsKey(e.Key()))
{
var result = CurrentMap[e.Key()];
if (result.MyAction == null)
{
CurrentMap = result.MyMap;
PressedKeys.Add(e.Key());
Ambiguous = PressedKeys.Count == 1;
}
else
{
Skip = true;
if (DoLog) Log(string.Format("Action in {0}: {1}", HoldContext.WindowName, result.MyAction));
result.MyAction.Execute();
Skip = false;
Ambiguous = false;
}
Suppress(e);
}
else
{
//SendAmbiguousKeys();
//Reset();
//.........这里部分代码省略.........
示例2: HookManager_KeyUp
public void HookManager_KeyUp(object sender, KeyEventArgs e)
{
try
{
//Log("RMenu down? " + HookManager.IoHooks.GetKeyState((int)WindowsInput.Native.VirtualKeyCode.RMENU).ToString());
//Log("LMenu down? " + HookManager.IoHooks.GetKeyState((int)WindowsInput.Native.VirtualKeyCode.LMENU).ToString());
//Log("Menu down? " + HookManager.IoHooks.GetKeyState((int)WindowsInput.Native.VirtualKeyCode.MENU).ToString());
//Log("");
// This is a hack because sometimes during alt-tab the virtual alt key gets stuck down. So... we just force it back up at every opportunity. =(
//if (e.Key() == Meta)
//{
// Skip = true;
// (LControl | LShift | LMenu | RControl | RShift | RMenu | Alt | Tab | AltMod).DoUp();
// OtherWindowsInput.InputSimulator.SimulateKeyUp(OtherWindowsInput.VirtualKeyCode.RMENU);
// OtherWindowsInput.InputSimulator.SimulateKeyUp(OtherWindowsInput.VirtualKeyCode.LMENU);
// // alt + tab
// //(LMenu + Tab).DoUp();
// Skip = false;
//}
if (Ambiguous && PressedKeys.Contains(e.Key()))
{
Ambiguous = false;
Skip = true;
e.Key().DoPress();
Skip = false;
}
PressedKeys.RemoveAll(match => match == e.Key());
if (PressedKeys.Count == 0)
{
Reset();
}
if (Skip)
{
if (DoLog) Log("Skip Up " + e.Key().ToString());
return;
}
if (e.Key() == Meta)
{
Functions.ResetFunctionKeys();
}
}
catch (Exception exc)
{
Log(exc);
}
}