C++发送击键疑难解答
我使用的是 Windows 7 Ultimate 64 位。这是我在网上偶然发现的一个功能,以前使用过没有问题,但现在遇到了问题。无论我向它发送什么字符,它都只会发送一个正斜杠击键 /。 这是该函数:
void GenerateKey(int vk, BOOL bExtended)
{
KEYBDINPUT kb = {0};
INPUT Input = {0};
/* Generate a "key down" */
if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
/* Generate a "key up" */
ZeroMemory(&kb, sizeof(KEYBDINPUT));
ZeroMemory(&Input, sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
return;
}
这是我如何调用它的: 生成密钥('x',FALSE);
但是,我得到的不是 x,而是 /。任何人都可以看到出了什么问题吗? 我使用的是 Visual Studio 2008。
I am using Windows 7 Ultimate 64-bit. This is a function I stumbled across online and used before with no issues but now I am having a problem. Regardless of what character I send to it, it will just send a forward slash keystroke /.
Here is the function:
void GenerateKey(int vk, BOOL bExtended)
{
KEYBDINPUT kb = {0};
INPUT Input = {0};
/* Generate a "key down" */
if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
/* Generate a "key up" */
ZeroMemory(&kb, sizeof(KEYBDINPUT));
ZeroMemory(&Input, sizeof(INPUT));
kb.dwFlags = KEYEVENTF_KEYUP;
if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; }
kb.wVk = vk;
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
SendInput(1, &Input, sizeof(Input));
return;
}
Here's how I am calling it:
GenerateKey('x', FALSE);
However, instead of an x I get a /. Can anyone see what's going wrong?
I am using Visual Studio 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
KEYBDINPUT.wVk 是虚拟键码,而不是 ascii 字符。
http://msdn.microsoft.com/en-我们/library/ms646271(v=vs.85).aspx
KEYBDINPUT.wVk is a virtual key code, not an ascii char.
http://msdn.microsoft.com/en-us/library/ms646271(v=vs.85).aspx