Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
VB.NET General Discussion
Mouse command with Windows API SendInput function - why doesn't it work?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="VBobCat, post: 165460, member: 35906"] Dear friends, I would like to command mouse operations with Windows API SendInput function. So I wrote the code below, but it doesn't work. Can anyone point out what I am doing wrong here? Thank you very much. [XCODE=vb] Public Sub MouseMove(ByVal x As Integer, ByVal y As Integer) Dim iMove As INPUT iMove.type = INPUT_MOUSE iMove.u.mi.dwFlags = MOUSEEVENTF_MOVE iMove.u.mi.dx = x iMove.u.mi.dy = y Dim rmove = SendInput(1, {iMove}, Marshal.SizeOf(iMove)) End Sub Public Sub MouseClick() Dim iLeftDown, iLeftUp As INPUT iLeftDown.type = INPUT_MOUSE iLeftDown.u.mi.dwFlags = MOUSEEVENTF_LEFTDOWN iLeftUp.type = INPUT_MOUSE iLeftUp.u.mi.dwFlags = MOUSEEVENTF_LEFTUP Dim rdown = SendInput(1, {iLeftDown}, Marshal.SizeOf(iLeftDown)) Dim rup = SendInput(1, {iLeftUp}, Marshal.SizeOf(iLeftUp)) End Sub <DllImport("user32.dll", SetLastError:=True)> _ Private Function SendInput(ByVal cInputs As Integer, ByRef pInputs As INPUT(), ByVal cbSize As Integer) As Integer End Function Structure INPUT Public type As Integer Public u As InputUnion End Structure Private Const KEYEVENTF_KEYUP As Integer = &H2 Private Const INPUT_MOUSE As Integer = 0 Private Const INPUT_KEYBOARD As Integer = 1 Private Const INPUT_HARDWARE As Integer = 2 <StructLayout(LayoutKind.Explicit)> _ Structure InputUnion <FieldOffset(0)> Public mi As MOUSEINPUT <FieldOffset(0)> Public ki As KEYBDINPUT <FieldOffset(0)> Public hi As HARDWAREINPUT End Structure Structure MOUSEINPUT Public dx As Integer Public dy As Integer Public mouseData As Integer Public dwFlags As Integer Public time As Integer Public dwExtraInfo As IntPtr End Structure Private Const MOUSEEVENTF_MOVE = &H1 Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Const MOUSEEVENTF_RIGHTDOWN = &H8 Private Const MOUSEEVENTF_RIGHTUP = &H10 Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 Private Const MOUSEEVENTF_MIDDLEUP = &H40 Private Const MOUSEEVENTF_ABSOLUTE = &H8000 Structure KEYBDINPUT Public wVk As Short Public wScan As Short Public dwFlags As Integer Public time As Integer Public dwExtraInfo As IntPtr End Structure Structure HARDWAREINPUT Public uMsg As Integer Public wParamL As Short Public wParamH As Short End Structure [/XCODE] [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
VB.NET General Discussion
Mouse command with Windows API SendInput function - why doesn't it work?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom