如何在 C# 中使用 keybd_event 按住一个键
How can I hold down a Key using the keybd_event in C#
我目前正在尝试开发一个应用程序,使用户能够将击键发送到特定程序。我已经可以发送键并按下这样的特定键了:
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
keybd_event(key, 0, 0, 0); //Start holding the key down
keybd_event(key, 0, KEY_UP_EVENT, 0); //Stop holding the key down
在发送字母时按住 Shift 键已经将字母大写了。
但是,如果我按住一封信(例如将其发送到记事本),那么只写一次该信。如果我对我的物理键盘做同样的事情,它就会开始写信,直到我再次松手。有没有人知道我该如何管理它?
我已经尝试过秒表,但它也不起作用。
感谢@RaymondChen 解答了这个问题
Physical keyboards have a feature called "typematic" which autorepeats characters which are held down. You'll have to emulate that too.
如果要模拟重复击键,只需发送多个 KeyDown 和 KeyUP-Events。
我目前正在尝试开发一个应用程序,使用户能够将击键发送到特定程序。我已经可以发送键并按下这样的特定键了:
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
keybd_event(key, 0, 0, 0); //Start holding the key down
keybd_event(key, 0, KEY_UP_EVENT, 0); //Stop holding the key down
在发送字母时按住 Shift 键已经将字母大写了。 但是,如果我按住一封信(例如将其发送到记事本),那么只写一次该信。如果我对我的物理键盘做同样的事情,它就会开始写信,直到我再次松手。有没有人知道我该如何管理它?
我已经尝试过秒表,但它也不起作用。
感谢@RaymondChen 解答了这个问题
Physical keyboards have a feature called "typematic" which autorepeats characters which are held down. You'll have to emulate that too.
如果要模拟重复击键,只需发送多个 KeyDown 和 KeyUP-Events。