2
我知道AutoHotKey,但我想为自己制作自己的程序。使其每10秒按一次F5。我搜索了互联网和堆栈溢出,但没有找到解决方案如何模拟按键
有没有办法做到这一点在C或不?我正在使用和定位Windows 8.1
我知道AutoHotKey,但我想为自己制作自己的程序。使其每10秒按一次F5。我搜索了互联网和堆栈溢出,但没有找到解决方案如何模拟按键
有没有办法做到这一点在C或不?我正在使用和定位Windows 8.1
您想要使用SendInput
函数。以下代码每隔10秒向Windows发送一次密钥输入事件对。
#include <windows.h>
static const int delay_ms = 10000;
void sendF5(
UINT uTimerID,
UINT uMsg,
DWORD_PTR dwUser,
DWORD_PTR dw1,
DWORD_PTR dw2) {
INPUT input[2] = {0};
input[0].type = input[1].type =
INPUT_KEYBOARD;
input[0].ki.wVk =
input[1].ki.wVk = VK_F5;
input[1].ki.dwFlags =
KEYEVENTF_KEYUP;
input[0].ki.dwExtraInfo =
input[1].ki.dwExtraInfo =
GetMessageExtraInfo();
SendInput(2, input, sizeof(INPUT));
}
int WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PWSTR pCmdLine,
int nCmdShow) {
timeSetEvent(delay_ms, 1000,
sendF5, 0, TIME_PERIODIC);
return 0;
}
只使用标准C?那就不要。使用操作系统功能?好的。但既然你不告诉我们你的目标是什么操作系统,那真的不可能回答。请花些时间[阅读如何提出问题](http://stackoverflow.com/help/how-to-ask),然后编辑您的问题以添加更多详细信息和标签。 –
现在编辑问题。谢谢。我正在使用Windows 8.1并针对相同的系统。 –
['keybd_event'](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646304(v = vs.85).aspx)或['SendInput'](https:// msdn .microsoft.com/en-us/library/ms646310(VS.85).aspx) – Ryan