1

I am writing an application that receives data from an Arduino which is reading a Wii Nunchuk. The data is being received and parsed correctly however when I send the data using MOUSEEVENTF_MOVE, the mouse will only receive data in dx and not dy meaning only movement up and down. I have tried using static values (100, for example) as dy and still no success.

DllImport code:

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Sub mouse_event(dwFlags As Long, dx As Long, dy As Long, dwData As Long, dwExtraInfo As Long)
End Sub

Private Const MOUSEEVENTF_MOVE As Integer = &H1

Code used to move the mouse:

mouse_event(MOUSEEVENTF_MOVE, dx, dy, 0, 0)

Unless the mouse_event sub is laid out wrong, I have no idea what I'm doing wrong.

JohnHoulderUK
  • 639
  • 2
  • 8
  • 27
  • 1
    The mouse_event() winapi function has been deprecated for a *long* time, replaced by SendInput(). For a very good reason, mouse_event() is broken because it doesn't have any way to tell you that the function failed. Unlike SendInput(), it returns *bool*. So there is no way to find out that your [DllImport] declaration is completely wrong, using *Long* was only appropriate in VB6. The http://pinvoke.net web site is a decent place to find correct ones. – Hans Passant Mar 30 '14 at 14:32
  • Thanks Hans, that's definitely something I'll keep bookmarked for future projects! :) – JohnHoulderUK Mar 30 '14 at 14:44

1 Answers1

2

From microsoft about relative movement:

The system applies two tests to the specified relative mouse movement. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the system doubles the distance that resulted from applying the first threshold test. It is thus possible for the system to multiply specified relative mouse movement along the x or y axis by up to four times.

So you better use

Cursor.Position() = New Point(X, Y)

valter