Clicking Buttons Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Posts: 51
Joined: 01 Aug 2016, 11:53

Clicking Buttons

03 Jan 2018, 10:49

I am working on a script that will run on a variety of computers with different sized monitors. When making scripts I try to avoid using mouse clicks like the plague and do keyboard shortcuts instead, unfortunately, this button has no keyboard shortcut. Is there a best practice for clicking buttons?

- Using "MouseClick, left, 1010, 320" works fine on my computer assuming the window is maximized but as soon as it runs on someone else's computer with a different resolution, the mouse click misses the button.

-I've looked into the "PixelSearch, Px, Py, 650, 300, 880, 335, 0099FF, 0, Fast" command, to find the color of the button and click it. Is this the best solution and just try to set the search area to be large enough to find the button on different sized monitors?

-Are there functions to detect the size of the active window? If so, it seems like you could use Mouse Click 20% Max X Pixels, 10% Max Y Pixel. Would this relative positioning work? Is this what people are doing?

-Should I just set a variable at the top of the script and when I put the script on other computers just specify the location of the button? Seems very manual and not cool, but might be the most stable?

Thanks for any advice,

Andrew V. Romero
User avatar
Posts: 1200
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clicking Buttons

03 Jan 2018, 11:00

Can you maybe reach that button by pressing the Tab key (several times)?
That would be the first thing I would try to do.
Please use [code][/code] when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version:
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Clicking Buttons

03 Jan 2018, 11:26

Could this help?

Code: Select all

Gui,Add, Button, x33 y45 vBut1 gBut,I will be clicked in a second
Gui,Show, h100 w400, Prova
Gui_ID := WinExist("A")
gosub FindButton

	ControlGetPos, x,y,w,h, Button1, ahk_id %Gui_ID%
	MouseClick, Left,  x+w/2 , y+h/2

	MsgBox Clicked !!!!
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Posts: 51
Joined: 01 Aug 2016, 11:53

Re: Clicking Buttons

03 Jan 2018, 12:25

Scr1pter- I have tried all sort of variations of tab, alt-tab, alt buttons, function buttons, etc. Nothing seems to grant focus to the button in this application.

Odlanir- I didn't know you could use this type of logic with non-AHK functions. ControlGetPos is something I will have to investigate more although in running the documentation example for ControlGetPos, it isn't identifying any coordinates or buttons. Could this be because the application is a Citrix application?

Code: Select all

    Sleep, 100
    MouseGetPos, , , WhichWindow, WhichControl
    ControlGetPos, x, y, w, h, %WhichControl%, ahk_id %WhichWindow%
    ToolTip, %WhichControl%`nX%X%`tY%Y%`nW%W%`t%H%
Posts: 70
Joined: 04 Aug 2016, 04:27

Re: Clicking Buttons  Topic is solved

03 Jan 2018, 16:09

With Citrix you'll have no luck with Odlanir's solution. You can either try PixelSearch or ImageSearch
Posts: 51
Joined: 01 Aug 2016, 11:53

Re: Clicking Buttons

04 Jan 2018, 10:04

Thanks, I was suspecting Citrix might be causing the issue. I do look forward to trying ControlGetPos on other scripts.

Return to “Ask For Help”

Who is online

Users browsing this forum: blad4, Google [Bot], JKnight_xbt33, mikeyww, williams and 49 guests