Selecting elements without unique class name

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Selecting elements without unique class name

14 Dec 2020, 07:59

Hello!

We have a custom C++ app that I'd like to be able to setup some hotkey shortcuts to certain elements (buttons, etc) via AutoHotKey.

However, some elements, per the "Window Spy" ("Active Window Info") app that comes with the AHK package, are not unique from each other.

For example, see the attached screenshot from the app.

Notice the two buttons that the the cursor is hovered over both show the same class name in the "Active Window Info" app.
is there a way to select such elements besides using screen coordinates?
Image 1122.png
Image 1122.png (251.88 KiB) Viewed 2412 times
Image 1121.png
Image 1121.png (214.55 KiB) Viewed 2412 times
Thanks much for your time/help,
Shawn
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Selecting elements without unique class name

02 Feb 2021, 12:53

Would anyone have any comments on this?

Thanks much,
Shawn
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Selecting elements without unique class name

02 Feb 2021, 13:09

See if pressing Alt enables any keyboard shortcuts. ImageSearch is another option. If the same commands are also available through the program menu, that might also be a way.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Selecting elements without unique class name

02 Feb 2021, 21:04

Download ACC viewer https://www.autohotkey.com/boards/viewtopic.php?t=26201

run the script drag the cross to that button and see if you get a unique path and if it is detected as "push button".

If you do then ACC can be an option, you could post the path and ill help further.
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Selecting elements without unique class name

11 Feb 2021, 17:20

Many thanks to each of you for your help!

AHKStudent,
I downloaded ACC Viewer and here is the results for the Pull From ZenCart button:
AccViewerScreenshot.png
AccViewerScreenshot.png (102.98 KiB) Viewed 2285 times
Can you help further, regarding how to call this in the AutoHotKey script?
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Selecting elements without unique class name

15 Feb 2021, 17:27

Good day,

Would anyone have any comments on how to implement this?

Many thanks,
Shawn
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Selecting elements without unique class name

16 Feb 2021, 07:26

Try:

Code: Select all

#Include Acc.ahk ; https://github.com/sancarn/ACC.AHK
Path:= "4.1.4" ; pseudo path replace it with real one (w/o "P.")
ChildId:= 12
hwnd:= WinExist("ASAPCentral")
;ControlGet, hwnd, Hwnd,, TPanel3, ASAPCentral ;try to uncomment this line too 
Acc := Acc_Get("Object", Path, 0, "ahk_id " hwnd)
Acc.accDoDefaultAction(ChildId), Acc:= ""
ChildId is 0 if you got "Object" in the left-bottom corner. If you got e.g. "Child Id: 5" set it to 5, however then Path would not be available (N/A), so to retrieve the path you have to select the whole ToolBar.
[Edit]: Just remembered you posted Acc Viewer pic. So ChildId is 12. I'm pretty sure Path is wrong, so use Viewer in the link below and as said above select the whole ToolBar (frame all buttons) to get the Path.

P.s.: Acc Viewer RP3.5 (recently published, may have some quirks)
Last edited by rommmcek on 10 Apr 2021, 09:24, edited 2 times in total.
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Selecting elements without unique class name

17 Feb 2021, 17:04

Thank you rommmcek!

Here is what I got when I went over the Stock Orders button with Acc Viewer RP2:

Note: It would not allow me to select the complete toolbar if by "complete toolbar" you mean all of the buttons... but just individual buttons.
Image 025.png
Image 025.png (25.53 KiB) Viewed 2164 times
So what should the code look like, in this case?
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Selecting elements without unique class name

17 Feb 2021, 21:50

techmon wrote:
17 Feb 2021, 17:04
So what should the code look like, in this case?
As I posted above. Assign the Child Id: ChildId:= 22 and to get the Path, yes you have to select all the buttons.
First select one button then (holding LButton down) move the mouse slowly towards bottom or top edge of the button until frame gets bigger (hopefully to encompass all buttons tightly) then release LButton. If that does not work try the same on first button moving the mouse to the left or last button moving to the right.
You can use this scriptlet to move the mouse pixel by pixel

Code: Select all

Right:: MouseMove, 1, 0,, R
Left:: MouseMove, -1, 0,, R
Down:: MouseMove, 0, 1,, R
Up:: MouseMove, 0, -1,, R

^!Esc::
    SoundBeep, 2000
    SoundBeep, 1000
ExitApp
while holding LButton navigate the mouse with arrows to the desired edge of the button.
As I saw from your first post pic some buttons have gap in-between (e.g. Refresh Tasks and Pull From ZenCart), so you can try to navigate the Cross-Hair to that hiatus.
If all this does not work (either the frame stars to flicker or does not encompass all buttons) you have bad luck. Then we have to calculate the path manually. But before that you can try another tool. It usually yields correct path and Child Id in one go. (Select button, press Shif+Tab and click on GetPath in Accessible part of the displayed info).
techmon
Posts: 54
Joined: 16 May 2017, 13:30

Re: Selecting elements without unique class name

18 Feb 2021, 17:20

Thanks much Rommmcek.

I did get the RP2 viewer to find the Path then (I was able to select the whole horizontal bar of buttons with RP2)
Image 032.png
Image 032.png (30.53 KiB) Viewed 2107 times

Code: Select all

#Include Acc.ahk ; https://github.com/sancarn/ACC.AHK
Path:= "4.1.4" ; pseudo path replace it with real one (w/o "P.")
ChildId:= 12
hwnd:= WinExist("ASAPCentral")
;ControlGet, hwnd, Hwnd,, TPanel3, ASAPCentral ;try to uncomment this line too 
Acc := Acc_Get("Object", Path, 0, "ahk_id " hwnd)
Acc.accDoDefaultAction(ChildId), Acc:= ""
So here's the code I have so far, based on what you gave earlier.
What would be the final script to be able to click the Stock Orders button? and let's trigger it via Ctrl + 2. See screenshot below when that button is hovered over with the "Window Spy" tool that comes with AHK. (When I just tried moments ago, I was actually unable to just select that button after all, with the ACC Viewer, for some reason.
Image 032.png
Image 032.png (30.53 KiB) Viewed 2107 times
Many thanks for the assistance!
Shawn
Attachments
Image 033.png
Image 033.png (240.07 KiB) Viewed 2107 times
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Selecting elements without unique class name

18 Feb 2021, 17:46

Path Is for all buttons (in that toolbar) the same. So assigne Path:= "4.4.4.1.4" and to get ChildId select the desired buton and read the value at the bottom left corner of the Viewer. So given your previous pic it is 22 ChildId:= 22
If you have trouble to select (reselect) a button, try to restart the RP2 (maybe I have to rethink the initialization after all). Restarting the app (user interface) may help too.
Here is the whole code for Hotkey Ctrl + 2:

Code: Select all

#Include Acc.ahk ; https://github.com/sancarn/ACC.AHK
Path:= "4.4.4.1.4" ; pseudo path replace it with real one (w/o "P.")
ChildId:= 22

^2::
    hwnd:= WinExist("ASAPCentral")
    ;ControlGet, hwnd, Hwnd,, TPanel3, ASAPCentral ;try to uncomment this line too 
    ;ControlGet, hwnd, Hwnd,, TToolBar1, ASAPCentral ;try to uncomment this line too 
    Acc := Acc_Get("Object", Path, 0, "ahk_id " hwnd)
    Acc.accDoDefaultAction(ChildId), Acc:= ""
Return
Now you made some pretty basic questions! Are you familiar to get/copy the Acc.ahk library? Here is direct link. Acc.ahk must be in the same folder as your script (w/ Hotkey) above. Or just paste the library below this script (then you have to comment out the line: #Include Acc.ahk ; https://github.com/sancarn/ACC.AHK.

P.s.: When your done, hope it will work! If not try to get handle of the Control. Comment out hwnd:= WinExist("ASAPCentral") and uncomment one of the lines below (one at a time). Good luck!
User avatar
labrint
Posts: 379
Joined: 14 Jun 2017, 05:06
Location: Malta

Re: Selecting elements without unique class name

09 Feb 2022, 04:04

@rommmcek Took me forever to find this article but was exactly what I needed. This was my question on AHK 4 years ago.

viewtopic.php?f=76&t=54188

It works like a charm on my toolstrip, as well as other buttons.

This is a very important and somewhat overlooked aspect in AHK as the control function in AHK is limited without this library.

So as far as toolstrips go, this is amazing. But you need to give some examples of;

a) Systreeview32 (tree) (how to click and open individual nodes, and get their text or text of their child

b) Tables (how to click on Top left cell to highlight all cells)
User avatar
rommmcek
Posts: 1475
Joined: 15 Aug 2014, 15:18

Re: Selecting elements without unique class name

01 Mar 2022, 14:06

Nice to hear, it helped you! Add link in your thread to this one.
Not sure about Tree nor Tables. Open new thread in Ask For Help. If not me other will help you!

bye!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 263 guests