我想编写简单的程序
,在某些地方发送我的用户名和密码,例如,当我想登录网站时,我发现了this。听键盘的项目。
所以我有这个功能:
private void HookManager_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
private void HookManager_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
private void HookManager_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
}
当我按下 a
键时,我得到了这样的结果:
int value = e.KeyValue; // 65
Keys key = e.KeyCode; // A
所以我想知道如何捕捉特定的键盘组合
,而不是只有一个键
,例如Ctrl + l
?
最佳答案
您可以为 KeyDown 使用这样的代码:
if(e.KeyCode == Keys.F1 && (e.Alt || e.Control || e.Shift))
{
}
基于KeyEventArgs来自 MSDN 的文档:
A KeyEventArgs, which specifies the key the user pressed and whether any modifier keys (CTRL, ALT, and SHIFT) were pressed at the same time, is passed with each KeyDown or KeyUp event.
The KeyDown event occurs when the user presses any key. The KeyUp event occurs when the user releases the key. Duplicate KeyDown events occur each time the key repeats, if the key is held down, but only one KeyUp event is generated when the user releases the key.
The KeyPress event also occurs when a key is pressed. A KeyPressEventArgs is passed with each KeyPress event, and specifies the character that was composed as a result of each key press.
关于c#监听键盘组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53679937/