使用全局键盘挂钩(如下所示: Global keyboard capture in C# application),如何检测从事件中被按下的键盘?
答案 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
}
}