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
Clicking a specific button
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Clicking a specific button
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.
That way it will press the button without having the specific coordinates and instead find that position for you.
Re: Clicking a specific button
@MannyKSoSo:
But I thought ControlClick is like ControlSend, but used for mouse clicks.
I use it for example in such cases:
Or can it be used both for X/Y names AND ClassNNs?
E.g.
Regards
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
E.g.
Code: Select all
ControlClick, #SG32DTBUTTON51, Target application
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
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Clicking a specific button
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.
Re: Clicking a specific button
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!
#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!
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Clicking a specific button
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.
Re: Clicking a specific button
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
#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
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Clicking a specific button
Since you have your window active we can do this.
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).
Code: Select all
#ifWinactive, Sage 50 Accounts Professional - GRP(UK)LTD
^x::
ControlClick, Email, A,,,NA
Return
Re: Clicking a specific button
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
"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
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: Clicking a specific button
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.
Re: Clicking a specific button
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
Re: Clicking a specific button
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
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
Re: Clicking a specific button
Hi Just me, the window has flagged up "Did not find the button!"
Thanks
Thanks
Re: Clicking a specific button
What a pity! Please add another MsgBox to the script:
Does it show anything?
Code: Select all
...
WinGet, CtrlList, ControlListHwnd, %WinTitle%
MsgBox, %CtrlList% ; <<<< add
...
Re: Clicking a specific button
#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
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
Re: Clicking a specific button
Hi,
Ive tried it with the above. Dont know if Ive added the extra script correctly but getting the same message
Thanks
Ive tried it with the above. Dont know if Ive added the extra script correctly but getting the same message
Thanks
Re: Clicking a specific button
Any idead folks?
Thanks
Thanks
Re: Clicking a specific button
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
Re: Clicking a specific button
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
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
Re: Clicking a specific button
Then I get another window sorry saying did not find the button??
thanks
thanks
Who is online
Users browsing this forum: Araphen, CrowexBR, Google [Bot], haomingchen1998, mcd, rubeusmalfoy, ShatterCoder, spellegrnio1 and 89 guests