gpt4 book ai didi

c#监听键盘组合

转载 作者:行者123 更新时间:2023-11-30 14:45:27 27 4
gpt4 key购买 nike

我想编写简单的程序,在某些地方发送我的用户名和密码,例如,当我想登录网站时,我发现了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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com