How to click on the control position?

Get help with using AutoHotkey and its commands and hotkeys
m3user
Posts: 116
Joined: 17 Jan 2014, 18:11

How to click on the control position?

05 Aug 2017, 04:24

There are some controls on a Window I would need to click but have no control names/text in Window Spy. In the example I try to click on one of the calculator keys using relative Window position in Window Spy.

This works

Code: Select all

WinActivate, Calculator
Click, 50, 330
but why this does not?

Code: Select all

ControlClick, X50 Y330, Calculator
What's wrong with ControlClick method?
Vh_
Posts: 190
Joined: 17 Mar 2017, 22:06

Re: How to click on the control position?

05 Aug 2017, 12:25

For one, your coords click off the screen. Try this to click the 1.

WinActivate, Calculator
sleep, 10
ControlClick, x38 y257, Calculator
m3user
Posts: 116
Joined: 17 Jan 2014, 18:11

Re: How to click on the control position?

05 Aug 2017, 17:28

I think my coordinates are correct - used Window Spy, window relative coordinates. I use Windows 10 calculator and the first script correctly clicks number 7. Why the second one fails with the same coordinates?
m3user
Posts: 116
Joined: 17 Jan 2014, 18:11

Re: How to click on the control position?

06 Aug 2017, 13:03

Anyone knows why would first script work amd the other not?
User avatar
jeeswg
Posts: 5942
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to click on the control position?

06 Aug 2017, 15:24

I didn't have any problems with this:

Code: Select all

q:: ;click buttons (sometimes buttons are missed)
;Calculator (Windows 7)
vSleep := 300
CoordMode, Mouse, Window
WinActivate, Calculator
WinWaitActive, Calculator

ControlClick, Button5, A ;1
Sleep, % vSleep
ControlClick, Button11, A ;2
Sleep, % vSleep
ControlClick, Button16, A ;3
Sleep, % vSleep

Click, 225, 190 ;7
Sleep, % vSleep
ControlClick, X225 Y190, Calculator ;7
Sleep, % vSleep
ControlClick, X225 Y190, Calculator,,,, Pos ;7
return

w:: ;click buttons (sometimes buttons are missed)
;e.g. try this when the window isn't active
Sleep, % vSleep
ControlClick, X225 Y190, Calculator ;7
Sleep, % vSleep
ControlClick, X225 Y190, Calculator,,,, Pos ;7
return
You might like to see if AccViewer can identify the GUI elements:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

An example using Acc:

Code: Select all

;an example using Acc functions
;Acc can be used to send clicks to (perform the default action for)
;windows/controls/GUI elements
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
q:: ;Calculator (Windows 7) - click 7 button
ControlGet, hCtl, Hwnd,, Button3, A ;7
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
oAcc.accDoDefaultAction(0)
oAcc := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: electrone77, Google [Bot], MannyKSoSo, scriptor2016, sinkfaze, SOTE and 181 guests