- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我尝试使用 SendInput
来同时发送多个按键按下/按键释放。数组和 vector 具有正确的信息,但由于某种原因,它只是没有按下任何东西。为什么?
我已经尝试从数组和 vector 中选取一个元素并使用 SendInput
按下/释放键,它工作正常。
#include <iostream>
#include <Windows.h>
#include <vector>
class movement
{
public:
std::vector<INPUT> inputs;
void Key(std::vector<INPUT> INPUTkeys)
{
INPUT * inputs = new INPUT[INPUTkeys.size()];
for (int i = 0; i < INPUTkeys.size(); i++)
inputs[i] = INPUTkeys.at(i);
SendInput(INPUTkeys.size(), inputs, sizeof(inputs));
delete[] inputs;
}
void prepareInput(INPUT &input, int key, bool down)
{
input.type = INPUT_KEYBOARD;
input.ki.dwExtraInfo = NULL;
input.ki.time = NULL;
input.ki.wScan = NULL;
input.ki.wVk = key;
if (down)
input.ki.dwFlags = 0;
else
input.ki.dwFlags = KEYEVENTF_KEYUP;
}
};
movement oMovement;
void main()
{
while (!GetAsyncKeyState(VK_SPACE))
Sleep(1);
std::vector<INPUT> inputs;
INPUT input;
oMovement.prepareInput(input, 'U', true);
inputs.push_back(input);
oMovement.prepareInput(input, 'S', true);
inputs.push_back(input);
oMovement.prepareInput(input, 'X', true);
inputs.push_back(input);
oMovement.Key(inputs);
inputs.clear();
oMovement.prepareInput(input, 'U', false);
inputs.push_back(input);
oMovement.prepareInput(input, 'S', false);
inputs.push_back(input);
oMovement.prepareInput(input, 'X', false);
inputs.push_back(input);
oMovement.Key(inputs);
inputs.clear();
system("pause");
}
最佳答案
您将指针的大小作为第三个参数传递给 SendInput
,而它应该是 INPUT
结构的大小。您还应该检查结果(至少在 Debug模式下):
void Key(std::vector<INPUT> & INPUTkeys) // pass by reference to prevent copying
{
::UINT const sent_events_count
{
SendInput
(
static_cast<::UINT>(INPUTkeys.size())
, INPUTkeys.data()
, sizeof ::INTPUT
)
};
assert(INPUTkeys.size() == sent_events_count);
}
关于c++ - 输入/vector 数组不适用于 SendInput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49066645/
我正在使用SendInput()进行鼠标移动,它想要INPUT结构。我正在使用相对运动,并且在有关此结构的docs中,在“备注”中说: Relative mouse motion is subject
我正在通过将字符串发送到备忘录来尝试 SendInput。我将 SendInput 命令与对 Memo.Lines.Add('....') 的调用混合在一起。令我惊讶的是,所有 Memo.Lines.
我正在使用以下标准 GenerateKey 代码: void GenerateKey ( int vk , BOOL bExtended) { KEYBDINPUT kb={0}; INPU
这个问题在这里已经有了答案: SendInput sends "num8" when I want to send "vk_up" ? How come? (3 个答案) 关闭 6 年前。 我需要模
我想通过模仿键盘将 4 位数字的所有可能组合注入(inject)到不同的程序(例如记事本)中,但我终生无法弄清楚如何使用 SendInput() 函数,或者如果有更好的选择。 string code;
这个问题在这里已经有了答案: How to detect if keystroke was emulated by keybd_event or SendInput? (2 个答案) 关闭 11 个
=) 我在 Windows7 笔记本电脑上使用 C++(不是 VC++)。 我对这种从当前位置移动鼠标 x/y 的方法有疑问。每次它为鼠标事件调用发送输入时,它都会移动鼠标,但也会关闭我的屏幕(相当于
我想用下面的代码以编程方式将鼠标运动合成到屏幕上的一个点 (100,100),但它移动到左上角。有什么问题吗? #include "stdafx.h" #include int main() {
我正在尝试使用 SendInput() 函数。我写了这段代码: #include #include #include #include #define WIN32_LEAN_AND_MEAN
我试图弄清楚 SendInput 函数的正确用法,以便我可以直接操纵屏幕上的光标,因此为了进行基本测试以了解其工作原理,我制作了这个应该将光标移动 10 的短片段右边的像素。理论上。 #include
在 Windows 中使用非英语输入键盘语言时,我无法模拟字符按键。 我尝试使用 KEYEVENTF_UNICODE 调用 SendInput(): KEYBDINPUT ki; INPUT inpu
我一直在尝试将一系列输入模拟到流程中。我唯一没有成功实现的是鼠标移动。我在网上找到了最接近的赌注: bool mouse_move(int x, int y) { INPUT input;
我想将从 android 客户端接收到的鼠标和键盘输入发送到在 Windows 上运行的游戏。SendInput 适用于我迄今为止开发的几乎所有游戏。但是要使 SendInput 正常工作,游戏必须是
是否可以在当前没有焦点的窗口上使用 sendInput 函数,并且可能通过使用多线程,同时将输入发送到多个最小化窗口,或者在您工作时将输入发送到一个窗口另一个窗口? 我想在 C# 中做这样的事情 提前
我有以下代码: INPUT Input = { 0 }; Input.type = INPUT_KEYBOARD; Input.mi.dwFlags = KEYEVENTF_EXTENDE
MSDN 指出 keybd_event 已被 SendInput 取代。在重写期间,我切换到使用 SendInput...这很好除了当尝试发送 Alt 键组合时。在 Win7 64 位系统上(尚未在其
我在执行物理鼠标单击时尝试使用SendInput移动鼠标(在Windows 10上)。如果我单击一次或两次,则效果很好,但是如果快速连续单击示例6次,则鼠标滞后几秒钟,则程序将停止响应。 是否有任何明
我希望有人可以提供帮助,我试图找到一个模拟键盘命令的 SendInput 代码示例,我希望找到记事本窗口并输入测试消息。 我最初在我正在处理的项目中使用了 SendKeys,SendKeys 功能使我
我正在尝试创建一个虚拟键盘,它使用 SendInput 方法模拟键盘,如下所示: public static void SendKeyDown(System.Windows.Forms
为了模拟一些按键,我必须向那里发送扫描代码,为此我使用 SendInput() WinAPI 中的函数,在大多数情况下都可以正常工作,但是如何使用它来发送“暂停”等键的扫描码呢?该 key 生成 6
我是一名优秀的程序员,十分优秀!