Clicking a specific button

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Clicking a specific button

25 Oct 2018, 05:38

Hi,

Amateur here Ive got to grips with ifwin active. But how do I click a specific button without just using mouse co-ordinates like below.

This button has different ClassNN on diff screen but always same text name.

ClassNN: #SG32DTBUTTON51
Text: Email

Can I change my intial mouse co-ord click so it clicks the button via text name

#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^e::
CoordMode, Mouse, Screen
Click 517,72
Sleep, 2500
Click 227,1061
Sleep, 500
Click 227,1061
Sleep, 500
Click 31, 309
Sleep, 500
Click 342, 284
Return
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Clicking a specific button

25 Oct 2018, 07:23

You can use ControlClick https://autohotkey.com/docs/commands/ControlClick.htm
That way it will press the button without having the specific coordinates and instead find that position for you.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Clicking a specific button

25 Oct 2018, 07:28

@MannyKSoSo:
But I thought ControlClick is like ControlSend, but used for mouse clicks.
I use it for example in such cases:

Code: Select all

ControlClick, x556 y180, Logitech Gaming Software
Or can it be used both for X/Y names AND ClassNNs?
E.g.

Code: Select all

ControlClick, #SG32DTBUTTON51, Target application
Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Clicking a specific button

25 Oct 2018, 07:42

Indeed it is very similar to ControlSend, but it cannot send mouse clicks to the window, which is why ControlClick is an option. You can use both coordinates and specify a control name, and if you really want you can specify coordinates along with a control which are retaliative with the control specified.
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

25 Oct 2018, 08:21

Hi, thanks for the help guys and ive read the links but im struggling. Cant get below to work with Text: Email or NN: #SG32DTBUTTON91


#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, #SG32DTBUTTON91
Return

#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, Email
Return

Many thanks in advance and thanks for your patience!
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Clicking a specific button

25 Oct 2018, 08:30

With the control Click, if you are using a specific control name, add the WinTitle to it that way it knows where to look otherwise it has no idea where to go as the WinActive part doesn't carry over.
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

25 Oct 2018, 09:00

Hi Manny, Ive used the following and doesnt work. Ideally dont want to use the NN button as it changes just the Text Email

#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, #SG32DTBUTTON91, Sage 50 Accounts Professional - GRP(UK)LTD, Email,,,NA
; NN, Wintitle, , Button text,,, (Read about the NA thing in your link)
Return

Thanks
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Clicking a specific button

25 Oct 2018, 09:35

Since you have your window active we can do this.

Code: Select all

#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, Email, A,,,NA
Return
A stands for the active window, and as long as the Email button is an email it should click it (I tested with one of my scripts using a random button and it clicked it).
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

25 Oct 2018, 09:53

Hi Manny I really appreciate that your time testing but still doesnt work?

"and as long as the Email button is an email" Its not an email its just a button that when once pressed will send a highlighted invoice (within sage accountancy) to outlook as a draft.

Thanks
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Clicking a specific button

25 Oct 2018, 14:44

Have you tried the class NN without the # in front of everything? I know you don't want to use the class NN, but there are ways to obtain it dynamically if needed.
just me
Posts: 9464
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Clicking a specific button

26 Oct 2018, 03:27

Hi, does this find the button when the Sage window is visible?

Code: Select all

#NoEnv
WinTitle := "Sage 50 Accounts Professional - GRP(UK)LTD"    ; the window's title
BtnClass := "#SG32DTBUTTON"                                 ; this leading part of the ClassNN should be fix!
BtnText  := "EMail"                                         ; the button's caption
BtnFound := False
WinGet, CtrlList, ControlListHwnd, %WinTitle%
Loop, Parse, CtrlList, `n
{
   HWND := A_LoopField
   WinGetClass, WinClass, ahk_id %HWND%
   If (WinClass <> BtnClass)
      Continue
   WinGetText, WinText, ahk_id %HWND%
   If (WinText <> BtnText)
      Continue
   BtnFound :=True
   ControlClick, , ahk_id %HWND%
   Break
}
If (BtnFound)
   MsgBox, 0, Found, Found and tried to click the button!
Else
   MsgBox, 16, Error, Did not find the button!
ExitApp
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

26 Oct 2018, 03:28

Hi buddy,

Unfortuantely still not working ive tried it both ways. The NN seems to of changed as well from yesterday when looking at it now on window spy


#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, #SG32DTBUTTON158, A,,,NA
Return

#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, SG32DTBUTTON158, A,,,NA
Return

Thanks
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

26 Oct 2018, 04:02

Hi Just me, the window has flagged up "Did not find the button!"

Thanks
just me
Posts: 9464
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Clicking a specific button

26 Oct 2018, 04:23

What a pity! Please add another MsgBox to the script:

Code: Select all

...
WinGet, CtrlList, ControlListHwnd, %WinTitle%
MsgBox, %CtrlList% ; <<<< add
...
Does it show anything?
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

26 Oct 2018, 05:17

#NoEnv
WinTitle := "Sage 50 Accounts Professional - GRP(UK)LTD" ; the window's title
BtnClass := "#SG32DTBUTTON" ; this leading part of the ClassNN should be fix!
BtnText := "EMail" ; the button's caption
BtnFound := False
WinGet, CtrlList, ControlListHwnd, %WinTitle%
Loop, Parse, CtrlList, `n
{
HWND := A_LoopField
WinGetClass, WinClass, ahk_id %HWND%
If (WinClass <> BtnClass)
Continue
WinGetText, WinText, ahk_id %HWND%
If (WinText <> BtnText)
Continue
BtnFound :=True
ControlClick, , ahk_id %HWND%
Break
}
If (BtnFound)
MsgBox, 0, Found, Found and tried to click the button!
Else
MsgBox, 16, Error, Did not find the button!
WinGet, CtrlList, ControlListHwnd, %WinTitle%
MsgBox, %CtrlList% ; <<<< add
ExitApp
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

26 Oct 2018, 08:01

Hi,

Ive tried it with the above. Dont know if Ive added the extra script correctly but getting the same message

Thanks
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

27 Oct 2018, 02:07

Any idead folks?

Thanks
just me
Posts: 9464
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Clicking a specific button

27 Oct 2018, 02:15

Try this version, please:

Code: Select all

#NoEnv
WinTitle := "Sage 50 Accounts Professional - GRP(UK)LTD"    ; the window's title
BtnClass := "#SG32DTBUTTON"                                 ; this leading part of the ClassNN should be fix!
BtnText  := "EMail"                                         ; the button's caption
BtnFound := False
WinGet, CtrlList, ControlListHwnd, %WinTitle%
MsgBox, 0, Found controls, %CtrlList% ; <<<<< added
Loop, Parse, CtrlList, `n
{
   HWND := A_LoopField
   WinGetClass, WinClass, ahk_id %HWND%
   If !InStr(WinClass, BtnClass) ; <<<<< changed
      Continue
   WinGetText, WinText, ahk_id %HWND%
   If (WinText <> BtnText)
      Continue
   BtnFound := True
   ControlClick, , ahk_id %HWND%
   Break
}
If (BtnFound)
   MsgBox, 0, Found, Found and tried to click the button!
Else
   MsgBox, 16, Error, Did not find the button!
ExitApp
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

08 Nov 2018, 09:40

Hi Just me,
Sorry for the delay.

Thanks for the reply...It wont let me cut and paste a print screen. But im getting a window called 'Found Controls' then a huge list:

0x50614
0x50616
etc like 50 of them

Any help as always appreciated.

Thanks
gazmoz17
Posts: 72
Joined: 14 Mar 2018, 09:37

Re: Clicking a specific button

08 Nov 2018, 09:41

Then I get another window sorry saying did not find the button??

thanks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, CrowexBR, Google [Bot], haomingchen1998, mcd, rubeusmalfoy, ShatterCoder, spellegrnio1 and 89 guests