c++中如何使用sendinput函数
how to use sendinput function C++
我不知道输入了什么参数,即使我看到了msdn的sendinput函数。
UINT WINAPI SendInput(
_In_ UINT nInputs,
_In_ LPINPUT pInputs,
_In_ int cbSize
);
上面的参数是什么意思,我需要为它们创建什么?还有,打字。wScan,吻。时间,吻。dwExtraInfo,吻。wVk, ki.dwFlags上面的宾语是什么意思,还有其他经常使用的宾语吗?
UINT
为无符号整数类型。_In_
表示参数是您发送到函数中的输入参数。这与输出参数相反,后者是您发送的内容,函数将填充。
LPINPUT
结构定义如下:
typedef struct tagINPUT {
DWORD type;
union
{
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
} INPUT, *PINPUT, FAR* LPINPUT;
所以它看起来像一个DWORD加上一些其他结构的并集。参考WinUser.h获取更多信息。
DWORD
是32位无符号整数(源):
DWORD是一个32位无符号整数(范围:0到4294967295)小数)。因为DWORD是无符号的,所以它的第一个位(最高有效位)不为签名保留位(MSB)。此类型声明为
: typepedef unsigned long DWORD, *PDWORD;
MOUSEINPUT
typedef struct tagMOUSEINPUT {
LONG dx;
LONG dy;
DWORD mouseData;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} MOUSEINPUT, *PMOUSEINPUT, FAR* LPMOUSEINPUT;
KEYBDINPUT
typedef struct tagKEYBDINPUT {
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT, FAR* LPKEYBDINPUT;
HARDWAREINPUT
typedef struct tagHARDWAREINPUT {
DWORD uMsg;
WORD wParamL;
WORD wParamH;
} HARDWAREINPUT, *PHARDWAREINPUT, FAR* LPHARDWAREINPUT;
WORD
, LONG
, ULONG
和ULONG_PTR
都在MSDN页面上定义良好(见右侧栏)
下面是一个使用SendInput
的例子,可以很容易地通过谷歌找到(来源):
//
// 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;
}
你问题的另一部分:
同样,键入,ki。wScan,吻。时间,吻。dwExtraInfo,吻。wVk, ki.dwFlags上面的对象是什么意思
我相信你指的是来自MSDN页面的这段代码:
// 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;
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用不带参数的函数访问结构元素
- 代码在main()中运行,但在函数中出现错误
- 内置函数可查看CPP中的成员变量
- 如何获取std::result_of函数的返回类型
- 如何在c++中为模板函数实例创建快捷方式
- c++中如何使用sendinput函数