【发布时间】:2017-09-26 19:59:21
【问题描述】:
我写了一个模拟点击特定按钮的简单程序。我努力将 'a' 转换为 0x41。
#include <iostream>
#include <Windows.h>
#define WINVER 0x0500
int main() {
INPUT ip;
// Pause for 5 seconds.
Sleep(5000);
// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
// Press the "A" key
ip.ki.wVk = 0x41; // virtual-key code for the "a" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
// Release the "A" key
ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
return 0;
}
编译并执行以下代码后,它确实单击“a”,这是正确的。但是当我将 ip.ki.wVk 中的值更改为 for ex 时。 (int)'a' 它的行为不同。
ip.ki.wVk = 0x41; //gives me "a" which is correct
ip.ki.wVk = 65 //the same as above which is good;
但是
ip.ki.wVk = int('a')//gives "1";
【问题讨论】:
-
如果你只使用
ip.ki.wVk = 'a'会发生什么? -
'a'是0x61和061是'1'要么是奇怪的巧合,要么是某个地方的拼写错误 -
虚拟键码与ascii字符不同。 msdn.microsoft.com/de-de/library/windows/desktop/…
-
"gives "1"是什么意思?你的意思是它给出了第一名?还是数字1?还是别的什么? -
与您的问题无关,但
#define WINVER 0x0500应该在#include <windows.h>之前