【发布时间】:2015-01-19 07:08:26
【问题描述】:
所以我正在制作一个程序来模拟按键“a”,然后使用我的 Enter 键功能按 Enter,但是该功能不起作用。当我运行程序时,它会按下 a 键,但似乎函数 hitDaEnterKey 根本不起作用。我做错了什么?
#define WINVER 0x0500
#include <windows.h>
int hitDaEnterKey()
{
INPUT ip;
// Press and release Enter Key
ip.ki.wVk = 0x0D;
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
// release
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
return 0;
}
int main()
{
// This structure will be used to create the keyboard
// input event.
INPUT ip;
Sleep(2500);
// 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));
hitDaEnterKey();
return 0;
}
【问题讨论】:
-
如果不行就是代码坏了。
-
@SANICTHEHEDGEHOGOnononymus 请注意,由于您的问题不符合网站的质量标准,因此您收到了轻率/讽刺的 cmets。您可以尝试reading the FAQ 并改进您的问题,而不是称其他用户为“Sherlock”。
-
您没有在该函数中指定输入类型