因此,基本上,我具有此功能,该功能每隔(在此处插入数字)毫秒释放一次W键,并且在按住W键时可以正常工作,但是由于某种原因,有时它在释放它后不会再次按该键,我真的不确定为什么会这样。是的,我也尝试过SendMessage
。
我还需要PostMessage
或SendMessage
,因为我发送给它的进程没有注册SendInput
击键。 SendInput会容易得多,但根本无法正常工作。这是我的代码:
struct extraKeyInfo
{
unsigned short repeatCount;
unsigned char scanCode;
bool extendedKey, prevKeyState, transitionState;
operator unsigned int()
{
return repeatCount | (scanCode << 16) | (extendedKey << 24) |
(prevKeyState << 30) | (transitionState << 31);
}
};
while (true)
{
if (wtap_check && ((GetAsyncKeyState(87) & 0x8000) == 0x8000))
{
if (click_check && mouse_down)
{
extraKeyInfo lParam = {};
//lParam.scanCode = MapVirtualKey(tagKBDLLHOOKSTRUCT::vkCode, MAPVK_VK_TO_VSC);
lParam.repeatCount = 1;
lParam.prevKeyState = true;
lParam.transitionState = true;
PostMessage(hwnd_outra_win, WM_KEYUP, (WPARAM)0x0057, lParam);
std::this_thread::sleep_for(std::chrono::milliseconds(insertnumberhere));
lParam.repeatCount = 0;
lParam.prevKeyState = false;
lParam.transitionState = false;
//SendMessage(hwnd_outra_win, WM_KEYUP, 0, MAKELPARAM(x, y));
PostMessage(hwnd_outra_win, WM_KEYDOWN, (WPARAM)0x0057, lParam);
std::this_thread::sleep_for(std::chrono::milliseconds(insertnumberhere)));
}
}
}