Question Sending mouse clicks and test to a window

Joined
May 10, 2011
Messages
5
Programming Experience
Beginner
Hey guys,

I am new to VB.net, i did a course in it about 5 years ago, and could do simple programs, but lost most of my knowledge, because i have not used it in such a long time, now i want to do something and cant seem to get it right,

i have this game that i a play online, and i have a few accounts for it, so i would like to make a account logger, wher the usernames and passwords will be saved in a text file, and then i just open the vb program, select the username and the vb program will automatically set focus to the game window (which is windowed, not full screen).

Problem is just, the game client has 4 buttons, New Account, Play Game, About and Credits, i want to get a way for the VB program to set focus to the program(bring it to front, and then move the mouse to the coordinates of the play game button, goto coordinates of the username text box, click and write the username, same for password and then move to login button coordinates and click logon, wait a sec or two and move to either character 1, 2, 3's login button and click)

Can someone please be so kind to help me with this code? i tried google, but because i have not used VB in such a long time, i am having a hard time even reading the tutorial code,

Thanks!
 
This will all need to be done using the windows API to get control of a window and send clicks to it. I would suggest looking into something like AutoIT or AutoHotKey software for something like that, but it can definitely be done in VB.NET also using the Windows API.
 
This will all need to be done using the windows API to get control of a window and send clicks to it. I would suggest looking into something like AutoIT or AutoHotKey software for something like that, but it can definitely be done in VB.NET also using the Windows API.

I have done this with something very similar to autoIT, called scar, but i would like to get way from the scripts, and do it in a single executable exe, hence i want to do it with VB.

SCAR, works fine, but sometimes it is a bit laggy, causing the program to mistype, select the wrong char or sometimes it does not stop the script after logon.
 
Then the windows API calls is what you will need I believe FindWindow and SetForeground should be used to find and activate a window through the API. Then you can use the Mouse_Event api call to move and click the mouse as needed. Then you can use the KeyBD_Event function to perform whatever keystrokes you want.

VB.NET:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function mouse_event Lib "user32.dll" Alias "mouse_eventA" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean

'mouse constants
 Const MOUSEEVENTF_MOVE As Int32 = &H1 '  mouse move
    Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2 '  left button down
    Const MOUSEEVENTF_LEFTUP As Int32 = &H4 '  left button up
    Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8 '  right button down
    Const MOUSEEVENTF_RIGHTUP As Int32 = &H10 '  right button up
    Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20 '  middle button down
    Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40 '  middle button up
    Const MOUSEEVENTF_ABSOLUTE As Int32 = &H8000 '  absolute move
    Const MOUSEEVENTF_WHEEL As Int32 = &H800 ' wheel button rolled
'keybd constants
'still looking for these but pressed for time
 
Back
Top