UINT
是无符号整数类型。_In_
表示参数是一个input您发送到函数中的参数。这是反对output参数,这将是您发送的内容,函数将填写。
The LPINPUT
结构体定义如下:
typedef struct tagINPUT {
DWORD type;
union
{
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
} INPUT, *PINPUT, FAR* LPINPUT;
所以它看起来就像一个 DWORD 加上一些其他结构的联合。参考WinUser.h http://www.csee.umbc.edu/~squire/download/WinUser.h了解更多。
DWORD
是一个 32 位无符号整数 (source http://msdn.microsoft.com/en-us/library/cc230318.aspx):
DWORD 是 32 位无符号整数(范围:0 到 4294967295
十进制)。因为 DWORD 是无符号的,所以它的第一位(最高有效位)
位(MSB))不保留用于签名。该类型声明为
如下: 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
, and ULONG_PTR
都是明确定义的MSDN 页面 http://msdn.microsoft.com/en-us/library/cc230309.aspx(见右栏)
这是一个使用示例SendInput
可以通过谷歌搜索轻松找到(Source http://batchloaf.wordpress.com/2012/04/17/simulating-a-keystroke-in-win32-c-or-c-using-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、ki.time、ki.dwExtraInfo、ki.wVk、ki.dwFlags
上面的对象是什么意思
我相信你指的是这段代码MSDN 页面 http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx:
// 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));
该代码是由该页面上的另一个用户发布的;它不是文档的一部分。用户只需创建一个LPINPUT
结构命名为keyEvent
,然后访问KEYBDEVENT
部分结构:
KEYBDINPUT ki;