SolvedMouse Clicks And Sending Keys

Posts 1–4 of 4 · Page 1 of 1
Mouse Clicks And Sending Keys
does this code work? it doesnt for me.(engine.exe)
My
.Computer.Keyboard.SendKeys("W")

could someone help me get some version of sendkeys working?

and mouse clicks please
First, add this import to your class:

Code:
Imports System.Runtime.InteropServices
Then, add the following declarations and procedures to your code:

Code:
<DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, _
           CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", _
           ExactSpelling:=True, SetLastError:=True)> _
    Public Shared Function KeyBoardEvent(ByVal bVk As Byte, ByVal bScan As Byte, _
                              ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32) As Boolean
    End Function
    Const KeyUp As Byte = &H2
    Sub PressKey(ByVal Key As Keys)
        KeyBoardEvent(Key, 0, 0, 0)
        KeyBoardEvent(Key, 0, KeyUp, 0)
    End Sub
    <DllImport("user32.dll")> _
    Private Shared Sub MouseEvent(ByVal dwFlags As UInteger, ByVal dx As UInteger, ByVal dy As UInteger, ByVal dwData As UInteger, ByVal dwExtraInfo As Integer)
    End Sub
    <Flags()> _
    Private Enum MouseEventFlags
        LEFTDOWN = &H2
        LEFTUP = &H4
        RIGHTDOWN = &H8
        RIGHTUP = &H10
    End Enum
    Sub LeftMouseClick()
        MouseEvent(MouseEventFlags.LEFTDOWN, 0, 0, 0, 0)
        MouseEvent(MouseEventFlags.LEFTUP, 0, 0, 0, 0)
    End Sub
    Sub RightMouseClick()
        MouseEvent(MouseEventFlags.RIGHTDOWN, 0, 0, 0, 0)
        MouseEvent(MouseEventFlags.RIGHTUP, 0, 0, 0, 0)
    End Sub
    Sub MoveMouseTo(ByVal X As Integer, ByVal Y As Integer)
        Cursor.Position = New Point(X, Y)
    End Sub
Then, for pressing a key, call PressKey procedure from anywhere in the code like this:

Code:
PressKey(Keys.K)
The above line of code presses K key.

For a mouse click, use the following procedures:

Left Click:
Code:
LeftMouseClick()
Right Click:
Code:
RightMouseClick()
To move mouse to a particular point on screen, call this:

Code:
MoveMouseTo(0,0)
The above line moves mouse to Top Left corner of the screen.

Note that you may need to set focus to the game or application you are trying to send clicks or key presses.
Quote Originally Posted by Hassan View Post
First, add this import to your class:

Code:
Imports System.Runtime.InteropServices
Then, add the following declarations and procedures to your code:

Code:
<DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, _
           CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", _
           ExactSpelling:=True, SetLastError:=True)> _
    Public Shared Function KeyBoardEvent(ByVal bVk As Byte, ByVal bScan As Byte, _
                              ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32) As Boolean
    End Function
    Const KeyUp As Byte = &H2
    Sub PressKey(ByVal Key As Keys)
        KeyBoardEvent(Key, 0, 0, 0)
        KeyBoardEvent(Key, 0, KeyUp, 0)
    End Sub
    <DllImport("user32.dll")> _
    Private Shared Sub MouseEvent(ByVal dwFlags As UInteger, ByVal dx As UInteger, ByVal dy As UInteger, ByVal dwData As UInteger, ByVal dwExtraInfo As Integer)
    End Sub
    <Flags()> _
    Private Enum MouseEventFlags
        LEFTDOWN = &H2
        LEFTUP = &H4
        RIGHTDOWN = &H8
        RIGHTUP = &H10
    End Enum
    Sub LeftMouseClick()
        MouseEvent(MouseEventFlags.LEFTDOWN, 0, 0, 0, 0)
        MouseEvent(MouseEventFlags.LEFTUP, 0, 0, 0, 0)
    End Sub
    Sub RightMouseClick()
        MouseEvent(MouseEventFlags.RIGHTDOWN, 0, 0, 0, 0)
        MouseEvent(MouseEventFlags.RIGHTUP, 0, 0, 0, 0)
    End Sub
    Sub MoveMouseTo(ByVal X As Integer, ByVal Y As Integer)
        Cursor.Position = New Point(X, Y)
    End Sub
Then, for pressing a key, call PressKey procedure from anywhere in the code like this:

Code:
PressKey(Keys.K)
The above line of code presses K key.

For a mouse click, use the following procedures:

Left Click:
Code:
LeftMouseClick()
Right Click:
Code:
RightMouseClick()
To move mouse to a particular point on screen, call this:

Code:
MoveMouseTo(0,0)
The above line moves mouse to Top Left corner of the screen.

Note that you may need to set focus to the game or application you are trying to send clicks or key presses.

Thanks bro


PS: do you know a program or anyway i can find the exact X and Y?
Quote Originally Posted by speedforyou View Post



Thanks bro


PS: do you know a program or anyway i can find the exact X and Y?
Something with:
Dim X As Integer = Cursor.Position.X
Dim Y As Integer = Cursor.Position.Y

?
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us