Ejemplo n.º 1
0
        /*
         * public override IntPtr HookProcedure(int nCode, IntPtr wParam, IntPtr lParam)
         * {
         *  var eventKeyDown = (wParam == (IntPtr)WM_KEYDOWN) ? "KeyDown " : "";
         *  var eventSysKeyDown = (wParam == (IntPtr)WM_SYSKEYDOWN) ? "SysKeyDown " : "";
         *  var eventKeyUp = (wParam == (IntPtr)WM_KEYUP) ? "KeyUp " : "";
         *  var eventSysKeyUp = (wParam == (IntPtr)WM_SYSKEYUP) ? "SysKeyUp " : "";
         *  var wkb = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         *  var wvkCode = (int)wkb.vkCode;
         *  var vk = KeyMapConverter.KeyCodeToKey(wvkCode);
         *
         *  Logger.WriteLine($"{nCode} : {vk} : {eventKeyDown}{eventSysKeyDown}{eventKeyUp}{eventSysKeyUp}");
         *
         *  if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN))
         *  {
         *      var kb = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         *      var vkCode = (int)kb.vkCode;
         *      if (this.isModifier(vkCode))
         *      {
         *          if (! this.Modifiers.Contains(vkCode))
         *          {
         *              this.Modifiers.Add(vkCode);
         *          }
         *          else
         *          {
         *              // KeyDown 時にすでに同じ Modifier が存在していた場合
         *              // ある Modifier を二重に押していることになる
         *              // なにか問題が発生しているときなので、いったん削除する
         *              this.Modifiers.Remove(vkCode);
         *          }
         *      }
         *      else
         *      {
         *          this.OnKeyDownEvent(vkCode);
         *      }
         *  }
         *  else if (nCode >= 0 && (wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYUP))
         *  {
         *      var kb = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         *      var vkCode = (int)kb.vkCode;
         *      if (this.isModifier(vkCode))
         *      {
         *          if (this.Modifiers.Contains(vkCode))
         *          {
         *              this.Modifiers.Remove(vkCode);
         *          }
         *      }
         *      else
         *      {
         *          this.OnKeyUpEvent(vkCode);
         *      }
         *  }
         *
         *  if (!this.callNextHook)
         *  {
         *      return new IntPtr(1);
         *  }
         *
         *  return base.HookProcedure(nCode, wParam, lParam);
         * }
         */

        protected bool isModifier(int keyCode)
        {
            var key = KeyMapConverter.KeyCodeToKey(keyCode);

            return(key == OriginalKey.LeftWindows ||
                   key == OriginalKey.RightWindows ||
                   key == OriginalKey.LeftCtrl ||
                   key == OriginalKey.RightCtrl ||
                   key == OriginalKey.LeftShift ||
                   key == OriginalKey.RightShift ||
                   key == OriginalKey.LeftAlt ||
                   key == OriginalKey.RightAlt);
        }
Ejemplo n.º 2
0
        private void InterceptKeyboard_KeyDownEvent(object sender, InterceptKeyboard.OriginalKeyEventArg e)
        {
            var key = KeyMapConverter.KeyCodeToKey(e.KeyCode);

            Debug.WriteLine("Keydown KeyCode {0}", key);

            if (e.equalsModifiers(new int[] { (int)OriginalKey.LeftWindows }))
            {
                Debug.WriteLine("With LeftWindows");
            }

            /*
             * if ( key == OriginalKey.LeftWindows)
             * {
             *  interceptKeyboard.callNextHook = false;
             * } else
             * {
             *  interceptKeyboard.callNextHook = true;
             * }
             */
        }
Ejemplo n.º 3
0
            /**
             * <summary>
             * 現在のキーイベントを文字列として戻す
             * </summary>
             */
            override public string ToString()
            {
                var key = KeyMapConverter.KeyCodeToKey(this.KeyCode);

                if (this.Modifiers.Length == 0)
                {
                    return($"{key}");
                }

                /*
                 * var modifiers = "";
                 * for (int i = 0; i < this.Modifiers.Length; i++)
                 * {
                 *  var mk = KeyMapConverter.KeyCodeToKey(this.Modifiers[i]);
                 *  modifiers += mk + " ";
                 * }
                 */
                var modifiers = string.Join(" + ", this.Modifiers.Select(x => KeyMapConverter.KeyCodeToKey(x)));

                return($"{modifiers} + {key}");
            }
Ejemplo n.º 4
0
 private void InterceptKeyboard_KeyUpEvent(object sender, InterceptKeyboard.OriginalKeyEventArg e)
 {
     Debug.WriteLine("Keyup KeyCode {0}", KeyMapConverter.KeyCodeToKey(e.KeyCode));
 }
Ejemplo n.º 5
0
            /**
             * <summary>
             * 指定されたキーコード、修飾キーが押されたかを判別する
             * </summary>
             */
            public bool Equals(OriginalKey key, int[] modifiers)
            {
                var originalKey = KeyMapConverter.KeyCodeToKey(this.KeyCode);

                return(key == originalKey && this.EqualsModifiers(modifiers));
            }