C++ SendInput()
C++ SendInput()
我想创建一个程序,它每按一次击键就只发送一次击键。我在这个程序上遇到了问题,因为即使我停止按键,它也会继续发送击键。
例如;如果按"UP",它将继续向上按,直到我按另一个键。
你能帮我这个吗?
谢谢
int main()
{
// This structure will be used to create the keyboard
// input event.
INPUT ip;
while(1)
{
if (GetAsyncKeyState(VK_UP) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x26; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
if (GetAsyncKeyState(VK_DOWN) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x28; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
if (GetAsyncKeyState(VK_RIGHT) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.wVk = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x27; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
if (GetAsyncKeyState(VK_LEFT) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x25; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
}
// Exit normally
return 0;
}
您可以保留是否是第一次单击按钮的状态。然后,您只需在释放时重置它。下面是其中一个按钮的示例。
bool up_pressed = false;
int main()
{
if (GetAsyncKeyState(VK_UP) < 0)
{
if (!up_pressed)
{
up_pressed = true;
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x26; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
}
else
{
up_pressed = false;
}
}
嗨,您可以使用以下代码:SendKeys::Send("{UP}");
相关文章:
- 使用 SendInput 或 mouse_event 不适用于 clock()?
- SendInput()鼠标移动计算
- C++ SendInput()
- Implementing winapi(SendInput) with dart:ffi
- 如何检测击键是否被keybd_event或 SendInput 模拟?
- C++ 上的 SendInput 不接受 Ctrl 和 Shift 帐户
- 将字符串传递到sendInput()(C )中
- SendInput() 无法正确管理 Alt 代码
- c++ winapi SendInput 意外行为
- C++SendInput没有按键
- VK_TAB在我的 c++ 程序中无法在 SendInput() 中工作
- C++-使用SendInput方法模拟按键,无法区分右键
- 使用SendInput锁定计算机
- 如何在SendInput中使用扩展扫描码
- 在Eclipse CDT中使用SendInput和MinGW
- 修饰符键与SendInput()配合使用很奇怪
- c++ SendInput在Windows Service中是可能的
- c++ win32 SendInput()
- SendInput -(鼠标移动模拟)
- 使用SendInput发送两个或多个字符