为什么我的函数在被调用时不起作用?
Why iisn't my function working when it's called?
所以我正在制作一个程序来模拟按键"a",然后使用我的回车键功能按回车键,但该功能不起作用。当我 运行 程序时,它会按 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;
}
int hitDaEnterKey()
{
INPUT ip;
// 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 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 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(&ip);
return 0;
}
所以我正在制作一个程序来模拟按键"a",然后使用我的回车键功能按回车键,但该功能不起作用。当我 运行 程序时,它会按 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;
}
int hitDaEnterKey()
{
INPUT ip;
// 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 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 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(&ip);
return 0;
}