Best Way to sendkeys and mouse click, rightclick, etc ?

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Best Way to sendkeys and mouse click, rightclick, etc ?

Post by ricardo »

Hi,

I have the need to control via sendkeys a software that its running in a VPS.
I spoke with the coder and there is no API, just send keys and mouse clicks.

I already found some sendkeys function (SendKeys procedure by PB) in the forum but do not include sending mouse left/right clicks and to find the buttons/controls handle on the window, mouse x,y clicks.

If possible i want to read the value of one cell in the listicon control.

Any help will be welcome.

*Im trying to control GSA SER, so just need to find and click the start/stop button, right click on one listview (or something similar) and use the mouse arrows to navigate in the menu options.
As i said, i only nee to find the button and fiund how to send mouse clicks.

Best Regards
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Best Way to sendkeys and mouse click, rightclick, etc ?

Post by ricardo »

Ok, i am on my way in most part.

Im just need to resolve something:

With the messageboxes that the software i am controlling are showing.
I can easily find the title, but i need to be able to read the text, does anybody know how to achieve it?

#WM_GETTEXT?
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Best Way to sendkeys and mouse click, rightclick, etc ?

Post by ricardo »

Its not the best way i guess, but until now i found that simulating CTRL+C i get the text in the MsgBox

Code: Select all

keybd_event_(#VK_CONTROL,0,0,0)
keybd_event_ (#VK_C, 0, 0, 0)
keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
Text$ = GetClipboardText()
ARGENTINA WORLD CHAMPION
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Best Way to sendkeys and mouse click, rightclick, etc ?

Post by netmaestro »

Code: Select all

Procedure enummer(hwnd, lParam)
  cn$=Space(100)
  wt$ = Space(512)
  GetClassName_(hwnd, @cn$, 98)
  If cn$ = "Static"
    GetWindowText_(hwnd, @wt$, 510)
    Debug wt$
    ProcedureReturn 0
  Else
    ProcedureReturn 1
  EndIf
EndProcedure

Procedure gettext(void)
  Delay(50)
  Repeat
    hwnd = FindWindow_("#32770", "Title")
    Delay(1)
  Until hwnd<>0
  EnumChildWindows_(hwnd, @enummer(), 0)  
EndProcedure

CreateThread(@gettext(), 0)
MessageRequester("Title", "I'll take titties for 400 Alex")
BERESHEIT
JCV
Enthusiast
Enthusiast
Posts: 580
Joined: Fri Jun 30, 2006 4:30 pm
Location: Philippines

Re: Best Way to sendkeys and mouse click, rightclick, etc ?

Post by JCV »

This is what I use to send left mouse click to a window by coordinates.

Code: Select all

Macro MAKELPARAM(x, y)
  (y<<16) | x
EndMacro 

Procedure Click(x, y, times = 1, speed = 0)
  If times > 1
    times - 1
		For i = 0 To times
		  If hWnd
		    Debug "click (" + Str(x) + "," + Str(y) + ") : " + Str(i)
      PostMessage_(hWnd, #WM_LBUTTONDOWN, 0, MAKELPARAM(x, y))
      PostMessage_(hWnd, #WM_LBUTTONUP, 0, MAKELPARAM(x, y))
      EndIf
		  Delay(speed)
		Next
	Else
	  If hWnd
	    Debug "click (" + Str(x) + "," + Str(y) + ")"
      PostMessage_(hWnd, #WM_LBUTTONDOWN, 0, MAKELPARAM(x, y))
      PostMessage_(hWnd, #WM_LBUTTONUP, 0, MAKELPARAM(x, y))
    EndIf
	EndIf
EndProcedure

[Registered PB User since 2006]
[PureBasic 6.20][SpiderBasic 2.2]
[RP4 x64][Win 11 x64][Ubuntu x64]
Post Reply