C++ Troubleshooting Sending Keystrokes
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.
KEYBDINPUT.wVk is a virtual key code, not an ascii char.
http://msdn.microsoft.com/en-us/library/ms646271(v=vs.85).aspx
精彩评论