示例#1
0
        ///<summary>
        ///KeyboardHookedイベントを発生させる。
        ///</summary>
        ///<param name="e">イベントのデータ。</param>
        protected virtual void OnKeyboardHooked(KeyboardHookedEventArgs e)
        {
            KeyboardHookedEventHandler handler = Events[EVENT_KEYBOARD_HOOKED] as KeyboardHookedEventHandler;

            if (handler != null)
            {
                handler(this, e);
            }
        }
示例#2
0
 private int CallNextHook(int code, KeyboardMessage message, ref KeyboardState state)
 {
     if (code >= 0)
     {
         KeyboardHookedEventArgs e = new KeyboardHookedEventArgs(message, ref state);
         OnKeyboardHooked(e);
         if (e.Cancel)
         {
             return(-1);
         }
     }
     return(CallNextHookEx(IntPtr.Zero, code, message, ref state));
 }
示例#3
0
        private void KeyHookEvent(object sender, KeyboardHookedEventArgs e)
        {
            if (e.UpDown != KeyboardUpDown.UP)
            {
                return;
            }
            var keycode = (byte)e.KeyCode;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (keycode)
            {
            case (byte)Keys.Return:
                this.result = Result.OK;
                Close();
                return;

            case (byte)Keys.Escape:
                if (this._keyList.Count == 0)
                {
                    this.result = Result.CANCEL;
                    Close();
                    return;
                }
                break;
            }
            switch (this.keyType)
            {
            case KeyType.SINGLE:
                this._keyList.Clear();
                if (keycode == (byte)Keys.Escape)
                {
                    this.lblInputKey.Text = "Press Any Key";
                    return;
                }
                this.lblInputKey.Text = Key.KEY_TEXT[keycode];
                this._keyList.Add(keycode);
                break;

            case KeyType.MULTI:
                if ((byte)e.KeyCode == (byte)Keys.Escape)
                {
                    this.lblInputKey.Text = "Press Any Key";
                    this._keyList.Clear();
                    return;
                }
                if (this._keyList.Count == 0)
                {
                    this._keyList.Add(keycode);
                    this.lblInputKey.Text = Key.KEY_TEXT[keycode];
                }
                else
                {
                    this._keyList.Add(keycode);
                    this.lblInputKey.Text = this.lblInputKey.Text + " + " + Key.KEY_TEXT[keycode];
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }