0

我目前的代码是:

[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”坚持。

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

提前致谢

4

1 回答 1

2

我相信 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);
于 2012-02-17T22:47:27.353 回答