当前位置: 首页>>代码示例>>C#>>正文


C# KeyEventArgs.Key方法代码示例

本文整理汇总了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();
//.........这里部分代码省略.........
开发者ID:JordanFisher,项目名称:PinkyTwirl-CSharp,代码行数:101,代码来源:PinkyTwirl.cs

示例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);
            }
        }
开发者ID:JordanFisher,项目名称:PinkyTwirl-CSharp,代码行数:53,代码来源:PinkyTwirl.cs


注:本文中的System.Windows.Forms.KeyEventArgs.Key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。