SendInput Function

The SendInput function synthesizes keystrokes, mouse motions, and button clicks.

Syntax

UINT SendInput(      
    UINT nInputs,     LPINPUT pInputs,     int cbSize );

Parameters

nInputs
[in] Number of structures in the pInputs array.
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails.

Return Value

The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError.

Microsoft Windows Vista. This function fails when it is blocked by User Interface Privilege Isolation (UIPI). Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking.

Remarks

Microsoft Windows Vista. This function is subject to UIPI. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level.

The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput.

This function does not reset the keyboard's current state. Any keys that are already pressed when the function is called might interfere with the events that this function generates. To avoid this problem, check the keyboard's state with the GetAsyncKeyState function and correct as necessary.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows XP, Windows NT 4.0 Service Pack 3

See Also

Tags :


Community Content

Nytro RST
VB6 Problem
What did I wrong ?

Private Declare Function SendInput Lib "user32" (ByVal nInputs As Long, ByRef pInputs As INPUT_DATA, ByVal cbSize As Long) As Long

Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type

Private Type KEYBDINPUT
wVk As Long
wScan As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type

Private Type HARDWAREINPUT
uMsg As Long
wParamL As Long
wParamH As Long
End Type

Private Type INPUT_DATA
type As Long
mi As MOUSEINPUT
ki As KEYBDINPUT
hi As HARDWAREINPUT
End Type

Private Const INPUT_MOUSE As Long = 0
Private Const INPUT_KEYBOARD As Long = 1
Private Const INPUT_HARDWARE As Long = 2

Public Function SendKeybdInput(ByVal key As String)
Dim keydata As KEYBDINPUT, x As MOUSEINPUT, y As HARDWAREINPUT
Dim inputdata As INPUT_DATA

keydata.wVk = Asc(key)
keydata.dwExtraInfo = 0
keydata.dwFlags = 0
keydata.time = 1
keydata.wScan = 0

inputdata.ki = keydata
inputdata.hi = y
inputdata.mi = x
inputdata.type = INPUT_KEYBOARD

SendKeybdInput = SendInput(1, inputdata, Len(inputdata))
End Function


Tags :

Nice PPk
The ki, hi, mi share memory in INPUT structure
I don't know how to define a union in VB. You may try to seperate them in three VB struct, as below.

Private Type INPUT_MOUSE_DATA
type As Long
mi As MOUSEINPUT
End Type

Private Type INPUT_KEYBD_DATA
type As Long
ki As KEYBDINPUT
End Type

Private Type INPUT_HW_DATA
type As Long
hi As HARDWAREINPUT
End Type
Tags :

juicejams
WM_TOUCH
Will WM_TOUCH messages work with SendInput?
For example:

reset.mi.dwFlags = (MOUSEEVENTF_LEFTDOWN)

to be replaced with

reset.mi.dwFlags = (TOUCHEVENTF_DOWN)

SendInput(1,&reset,sizeof(reset));

?

Thank you
Tags :

noone123457890
Old DOS Applications
If you want to send keyboard input to very old applications (e.g. DOS applications) you should use keybd_event with appropriate INT 9 Make/Break codes.
Tags :

Page view tracker