Code:
''' <summary>
''' The mouse_event function synthesizes mouse motion and button clicks.
''' </summary>
''' <param name="dwFlags">Controls various aspects of mouse motion and button clicking. This parameter can be certain combinations of the following values.</param>
''' <param name="dx">The mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE.</param>
''' <param name="dy">The mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE.</param>
''' <param name="dwData">If dwFlags contains MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement.</param>
''' <param name="dwExtraInfo">An additional value associated with the mouse event.</param>
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As UInteger, ByVal dx As UInteger, ByVal dy As UInteger, ByVal dwData As UInteger, ByVal dwExtraInfo As ULong)
Public Enum MouseEvent_Flags As UInt32
MOUSEEVENTF_ABSOLUTE = &H8000 'The dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system.
MOUSEEVENTF_LEFTDOWN = &H2 'The left button is down.
MOUSEEVENTF_LEFTUP = &H4 'The left button is up.
MOUSEEVENTF_MIDDLEDOWN = &H20 'The middle button is down.
MOUSEEVENTF_MIDDLEUP = &H40 'The middle button is up.
MOUSEEVENTF_MOVE = &H1 'Movement occurred.
MOUSEEVENTF_RIGHTDOWN = &H8 'The right button is down.
MOUSEEVENTF_RIGHTUP = &H10 'The right button is up.
MOUSEEVENTF_XDOWN = &H80 'An X button was pressed.
MOUSEEVENTF_XUP = &H100 'An X button was released.
MOUSEEVENTF_WHEEL = &H800 'The wheel has been moved, if the mouse has a wheel. The amount of movement is specified in dwData.
MOUSEEVENTF_HWHEEL = &H1000 'The wheel button is tilted.
MOUSEEVENTF_VIRTUALDESK = &H4000 'Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE.
End Enum
If you wish to hold down MButton then:
Code:
Dim IsEndPressed As Boolean = False
Dim AfterEndRelease as boolean = false
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim endbutton As Boolean = GetAsyncKeyState(Keys.End)
If endbutton = True Then
If IsEndPressed = False Then
IsEndPressed = True
AfterEndRelease = True
mouse_event(MouseEvent_Flags.MOUSEEVENTF_MIDDLEDOWN , 0, 0, 0) 'Holds down Middle Mouse Button.
end If
Else
IsEndPressed = True
if AfterEndRelease = True then
AfterEndRelease = False
mouse_event(MouseEvent_Flags.MOUSEEVENTF_MIDDLEUP , 0, 0, 0) 'Releases Middle Mouse Button.
end if
End If
End Sub