- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
虽然看到msdn的sendinput函数,我也不知道输入了什么参数。
UINT WINAPI SendInput(
_In_ UINT nInputs,
_In_ LPINPUT pInputs,
_In_ int cbSize
);
以上参数是什么意思,我需要为它们创建什么?此外,键入,ki.wScan,ki.time,ki.dwExtraInfo,ki.wVk,ki.dwFlags上面的对象是什么意思,还有其他可能经常使用的对象吗?
最佳答案
UINT
是无符号整数类型。 _In_
表示参数是您发送到函数中的输入 参数。这与 output 参数相反,该参数将是您发送的内容,函数将填充。
LPINPUT
结构定义如下:
typedef struct tagINPUT {
DWORD type;
union
{
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
} INPUT, *PINPUT, FAR* LPINPUT;
所以它看起来像一个 DWORD 加上一些其他结构的 union 。引用 WinUser.h了解更多。
DWORD
是 32 位无符号整数 (source):
A DWORD is a 32-bit unsigned integer (range: 0 through 4294967295 decimal). Because a DWORD is unsigned, its first bit (Most Significant Bit (MSB)) is not reserved for signing. This type is declared as follows: typedef unsigned long DWORD, *PDWORD, *LPDWORD;
typedef struct tagMOUSEINPUT {
LONG dx;
LONG dy;
DWORD mouseData;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} MOUSEINPUT, *PMOUSEINPUT, FAR* LPMOUSEINPUT;
typedef struct tagKEYBDINPUT {
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT, FAR* LPKEYBDINPUT;
typedef struct tagHARDWAREINPUT {
DWORD uMsg;
WORD wParamL;
WORD wParamH;
} HARDWAREINPUT, *PHARDWAREINPUT, FAR* LPHARDWAREINPUT;
WORD
、LONG
、ULONG
和 ULONG_PTR
在 MSDN page 上都有明确定义(见右栏)
这是一个使用 SendInput
的示例,可以通过谷歌搜索 (Source) 轻松找到:
//
// keystroke.c - Pauses, then simulates a key press
// and release of the "A" key.
//
// Written by Ted Burke - last updated 17-4-2012
//
// To compile with MinGW:
//
// gcc -o keystroke.exe keystroke.c
//
// To run the program:
//
// keystroke.exe
//
// ...then switch to e.g. a Notepad window and wait
// 5 seconds for the A key to be magically pressed.
//
// Because the SendInput function is only supported in
// Windows 2000 and later, WINVER needs to be set as
// follows so that SendInput gets defined when windows.h
// is included below.
#define WINVER 0x0500
#include <windows.h>
int main()
{
// This structure will be used to create the keyboard
// input event.
INPUT ip;
// Pause for 5 seconds.
Sleep(5000);
// 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));
// Exit normally
return 0;
}
你问题的另一部分:
Also, type, ki.wScan, ki.time, ki.dwExtraInfo, ki.wVk, ki.dwFlags What do objects above mean
我相信您指的是 MSDN page 中的这段代码:
// IMPORTANT: Current keyboard layout 0xf0010413 (Netherland with USA kbd)!!!!!!!
WORD vkCode = 0x36; // '6'
INPUT keyEvent = {0};
keyEvent.type = INPUT_KEYBOARD;
keyEvent.ki.wVk = vkCode;
keyEvent.ki.wScan = MapVirtualKeyEx(vkCode, 0, (HKL)0xf0010413);
SendInput(1, &keyEvent, sizeof(keyEvent));
该代码是由页面上的另一个用户发布的;它不是文档的一部分。用户只需创建一个名为 keyEvent
的 LPINPUT
结构,然后访问该结构的 KEYBDEVENT
部分:
KEYBDINPUT ki;
关于c++ - 如何使用sendinput函数C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22419038/
我正在使用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
我是一名优秀的程序员,十分优秀!