c#虚拟键盘p/invoke移位习惯“;释放“;钥匙

本文关键字:习惯 释放 钥匙 键盘 虚拟 invoke | 更新日期: 2023-09-27 18:25:11

我当前的代码是:

[DllImport("user32.dll", SetLastError = true)] 
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);  
public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag 
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag 
public const int VK_RMENU = 0xA5;
keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_Q, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_Q, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

我根据需要获得资本Q,但问题是;Shift";棒。

之后的所有字母都是大写字母。获得小写的唯一方法是更改为大写锁定。我该如何解决这个问题?

提前感谢

c#虚拟键盘p/invoke移位习惯“;释放“;钥匙

我相信Cody Gray为您的问题提供了解决方案。只需将P/Invoke呼叫替换为:

keybd_event(VK_SHIFT, 0, 0, 0);
keybd_event(VK_Q, 0, 0, 0);
keybd_event(VK_Q, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);