|
-
Aug 17th, 2009, 01:00 PM
#1
Thread Starter
Lively Member
Need help with SendInput
I’m trying to achieve mouse movements with SendInput.
There is code that got from Pinvoke, http://www.pinvoke.net/default.aspx/user32.SendInput
Code:
<DllImport("user32.dll", SetLastError = True)> _
Private Shared Function SendInput(ByVal nInputs As Integer, ByRef pInputs As InputLanguage,
ByVal cbSize As Integer) As Integer
End Function
Public Class Form1
Private Declare Function SendInput Lib "user32.dll" (ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
Private Structure INPUT
Dim dwType As Integer
Dim mkhi As MOUSEKEYBDHARDWAREINPUT
End Structure
Private Structure KEYBDINPUT
Public wVk As Short
Public wScan As Short
Public dwFlags As Integer
Public time As Integer
Public dwExtraInfo As IntPtr
End Structure
Private Structure HARDWAREINPUT
Public uMsg As Integer
Public wParamL As Short
Public wParamH As Short
End Structure
<StructLayout(LayoutKind.Explicit)> _
Private Structure MOUSEKEYBDHARDWAREINPUT
<FieldOffset(0)> Public mi As MOUSEINPUT
<FieldOffset(0)> Public ki As KEYBDINPUT
<FieldOffset(0)> Public hi As HARDWAREINPUT
End Structure
Private 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
Const INPUT_MOUSE As UInt32 = 0
Const INPUT_KEYBOARD As Integer = 1
Const INPUT_HARDWARE As Integer = 2
Const KEYEVENTF_EXTENDEDKEY As UInt32 = &H1
Const KEYEVENTF_KEYUP As UInt32 = &H2
Const KEYEVENTF_UNICODE As UInt32 = &H4
Const KEYEVENTF_SCANCODE As UInt32 = &H8
Const XBUTTON1 As UInt32 = &H1
Const XBUTTON2 As UInt32 = &H2
Const MOUSEEVENTF_MOVE As UInt32 = &H1
Const MOUSEEVENTF_LEFTDOWN As UInt32 = &H2
Const MOUSEEVENTF_LEFTUP As UInt32 = &H4
Const MOUSEEVENTF_RIGHTDOWN As UInt32 = &H8
Const MOUSEEVENTF_RIGHTUP As UInt32 = &H10
Const MOUSEEVENTF_MIDDLEDOWN As UInt32 = &H20
Const MOUSEEVENTF_MIDDLEUP As UInt32 = &H40
Const MOUSEEVENTF_XDOWN As UInt32 = &H80
Const MOUSEEVENTF_XUP As UInt32 = &H100
Const MOUSEEVENTF_WHEEL As UInt32 = &H800
Const MOUSEEVENTF_VIRTUALDESK As UInt32 = &H4000
Const MOUSEEVENTF_ABSOLUTE As UInt32 = &H8000
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
But it doesn’t work for me I’m getting those errors:
Error 1 Identifier expected. C:\Documents and 2 91 WindowsApplication1
Error 2 Type 'StructLayout' is not defined. C:\Documents and 26 6 WindowsApplication1
Error 3 Type 'FieldOffset' is not defined. C:\Documents and 28 10 WindowsApplication1
Error 4 Type 'FieldOffset' is not defined. C:\Documents and 29 10 WindowsApplication1
Error 5 Type 'FieldOffset' is not defined. C:\Documents and 30 10 WindowsApplication1
Please help!
VB n00b with stupid questions
Home site keywen.com
-
Aug 17th, 2009, 01:52 PM
#2
Addicted Member
Re: Need help with SendInput
I dunno man, that's kind of a big nasty mess to do what SetCursorPos already does in like 2 lines.
Code:
Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Int32, _
ByVal y As Int32) As Int32
Code:
Call SetCursorPos(X, Y)
-
Aug 17th, 2009, 02:15 PM
#3
Thread Starter
Lively Member
Re: Need help with SendInput
Thanks bro, but I already knew that also you can use
Code:
Windows.Forms.Cursor.Position = New System.Drawing.Point(x, y)
But I don’t want my cursor to jump araound I want it to move from one point to another, like human would. Can you help me with this?
VB n00b with stupid questions
Home site keywen.com
-
Aug 17th, 2009, 07:36 PM
#4
Addicted Member
-
Aug 17th, 2009, 08:20 PM
#5
Addicted Member
Re: Need help with SendInput
Ok 1 thing for sure.
If you add Imports System.Runtime.InteropServices to the first line of your class, it should clear up your warnings.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|