Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
SendInput (user32)
.
Summary
The SendInput function synthesizes keystrokes, mouse motions, and button clicks to the currently active window
C# Signature:
/// <summary>
/// Synthesizes keystrokes, mouse motions, and button clicks.
/// </summary>
[DllImport("user32.dll")]
internal static extern UINT SendInput(
UINT nInputs,
[MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs,
int cbSize);
VB.NET Signature:
<DllImport("user32.dll", SetLastError:=True)> Private Shared Function SendInput(ByVal cInputs As Integer, ByRef pInputs As MOUSEINPUT, ByVal cbSize As Integer) As Integer
End Function
VB Signature:
Private Declare Function SendInput Lib "user32.dll" (ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
C# User-Defined Types:
Notes:
look over here.
2 "UINT" should be replaced by "uint"
Tips & Tricks:
Please add some!
User-Defined Field Types:
INPUT
Sample Code:
var pInputs = new[]
{
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S,
dwFlags = EnumLib.KEYEVENTF.KEYUP
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S,
dwFlags = EnumLib.KEYEVENTF.KEYUP
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S,
dwFlags = EnumLib.KEYEVENTF.KEYUP
}
}
};
var hWindow = Api.user32.FindWindow("notepad", null);
Api.user32.SetForegroundWindow(hWindow);
Thread.Sleep(2500);
Api.user32.SendInput(
(uint)pInputs.Length, pInputs, StructLib.INPUT.Size);
code
#region powershell yes it WORKS!! begin
[testing.windows]::SetForegroundWindow( ( Get-Process notepad |? { $.id in
( get-wmiobject win32process -filter "name='notepad.exe'" |% { if ( $.getowner().user eq $env:username ) { $ .processid } } ) } )[0].MainWindowHandle)
$_inputList = New-Object 'Collections.Generic.List[Testing.Windows3+INPUT]'
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::KEY_S } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::KEY_S ; dwFlags = $( [Testing.Windows3+KEYEVENTF]::KEYUP ) } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::MENU } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::KEY_E } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::MENU ; dwFlags = $( [Testing.Windows3+KEYEVENTF]::KEYUP ) } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::KEY_E ; dwFlags = $( [Testing.Windows3+KEYEVENTF]::KEYUP ) } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::CONTROL } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::KEY_F } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::CONTROL ; dwFlags = $( [Testing.Windows3+KEYEVENTF]::KEYUP ) } ) } ) } ) )
$inputList.Add( $( New-Object Testing.Windows3+INPUT Property { type = [Testing.Windows3+INPUT
TYPE]::KEYBOARD ; U = $( New-Object Testing.Windows3+InputUnion -Property { ki = $( New-Object Testing.Windows3+KEYBDINPUT Property @{ wVk = [Testing.Windows3+VirtualKeyShort]::KEY_F ; dwFlags = $( [Testing.Windows3+KEYEVENTF]::KEYUP ) } ) } ) } ) )
$inputArray = $ inputList.ToArray()
Start-Sleep 2 ; [Testing.Windows3]::SendInput($inputArray.count, $ inputArray, [Runtime.InteropServices.marshal]::SizeOf($_inputArray[0]))
#endregion powershell yes it WORKS!! end
[/code]
Documentation
Used by [user32.SendInput] to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.
6/20/2022 9:40:56 PM - -113.208.118.82
Click to read this page 11/10/2022 6:13:33 AM - -171.251.237.238
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).