如何检测GlobalKeyboardHook中按下了哪个键盘?

时间:2017-11-21 10:55:14

标签: c# wpf

使用全局键盘挂钩(如下所示: Global keyboard capture in C# application),如何检测从事件中被按下的键盘?

1 个答案:

答案 0 :(得分:-1)

这是一个例子:

keyBoardHook = new KeyboardHook(true);
keyBoardHook.KeyDown += KeyBoardHook_KeyDown;
keyBoardHook.KeyUp += KeyBoardHook_KeyUp;

private void KeyBoardHook_KeyUp(System.Windows.Forms.Keys key, bool Shift, bool Ctrl, bool Alt)
    {
        if (key == System.Windows.Forms.Keys.F1)
        {
            //do something
        }
    }

    private void KeyBoardHook_KeyDown(System.Windows.Forms.Keys key, bool Shift, bool Ctrl, bool Alt)
    {
        if (key == System.Windows.Forms.Keys.F1)
        {
            //do something
        }
    }