tags:

views:

4

answers:

0

I'm using the following code to simulate a mouseclick. However I get the following error message:

File I/O of a structure with field 'dwExtraInfo' of type 'IntPtr' is not valid

What am I missing here?

    Dim inputEvents(0) As Input
    Dim p As MOUSEKEYBDHARDWAREINPUT

    p.mi.dx = x
    p.mi.dy = y
    p.mi.mouseData = 0
    p.mi.dwFlags = MOUSEEVENTF_LEFTDOWN
    p.mi.dwExtraInfo = 0 // this is wrong i guess? Not setting it at all doesn't work either..

    inputEvents(0).dwType = 0
    inputEvents(0).mkhi = p

    SendInput(1, inputEvents(0), Len(inputEvents(0)))

Extra code info

Private Declare Function SendInput Lib "user32.dll" (ByVal cInputs As Integer, ByRef pInputs As Input, ByVal cbSize As Integer) As Integer
'Structure Input

Private Structure INPUT
    Dim dwType As Integer
    Dim mkhi As MOUSEKEYBDHARDWAREINPUT
End Structure

Public Structure KEYBDINPUT
    Public wVk As Short
    Public wScan As Short
    Public dwFlags As Integer
    Public time As Integer
    Public dwExtraInfo As IntPtr
End Structure

Public 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

Public 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