1

Consider the following list of elements in a focused standard win32 list control in a legacy Windows application that runs remotely (WindowSpy can't get its controls or text):

  • 110
  • 120
  • 210
  • 220
  • 221
  • 2211
  • 2213
  • 222
  • 2222
  • 2224
  • 223

See something similar in this fiddle https://jsfiddle.net/e56bnLmc/

I want to navigate to element "2222" using AutoHotkey.

If I type "120" the cursor scrolls to element "120".

If I type "2222" with each sucessive "2" the cursor scrolls to "210", then "220", then "221", then "2211". But not to element "2222". This shows in the provided fiddle in Firefox and Chrome on Windows 10, but not in Explorer or Edge.

I cannot use the arrow keys, because I am not using the keyboard, but AutoHotkey, to go to "2222". I know there is an element "2222" but not which is the next element (it could be "2223" or "230" or "310") nor the prior one (it could be "2221" or "222" or "140").

  • To clarify, this is on a legacy windows app, not in the browser? i.e., a 'SysListView32X' control when viewed using Window Spy with AutoHotkey? – JJohnston2 Sep 6 at 6:31
  • Not having done this before, I'm guessing the approach would be to determine the control ID, then figure out how to reference that using LV_GetText(), and then execute a loop to send the first digit--i.e., "2"--while reading back the selected value to see if it's the right one. And of course checking for rollover to exit if the first element detected is also detected later in the loop. I think the tricky part would be getting LV_GetText() to work with an external handle that is not part of a ListView being used in an AutoHotkey GUI. – JJohnston2 Sep 6 at 7:30
  • In fact, WindowSpy doesn't recognize class or controls. I realized it is a remote application running through some virtualization/remote desktop software from Citrix. I was hoping to find some key modifier or registry hack to make the list behave as other list control where "2222" works as expected. I'll post my convoluted solution without accepting it, in hopes of something better appears. – dmcontador Sep 6 at 10:52
  • The fiddle you posted was very helpful to see the problem in action – JJohnston2 Sep 6 at 15:31
0

I can get the job done using ImageSearch, searching for an image containing the text I want to find. I don't like this solution much, though.

I installed ImageMagick to generate the images. It is invoked from within the script.

If the list is long I have to loop clicking in the scrollbar (don't want to use PgDn here to avoid selecting items on the list).

I have to allow shade differences, due to hinting and subpixel representation of the text on screen, which I cannot replicate with ImageMagick. Through trial and error, I found that (for these small texts) passing *200 seemed to get matches despite different hinting, and not mistaking Z for 2, S for 5 or O for 0.

WindowMatch := "xxxx"
; End position of the scrollbar, to check if at the bottom or not (and click to next page)
ScrollPosX := 692
ScrollPosY := 518
Label := "2222"

RunWait magick.exe -size 45x11 xc:white -font Tahoma -pointsize 12 -draw "fill black  text 3`,10 ' %Label% '" label.png

WinActivate, %WindowMatch%
Loop {
    ImageSearch, FoundX, FoundY, 0,0, 200,1000, *200 label.png
    if (ErrorLevel = 1) {
        ; Find Light grey which means scroll bar NOT at the bottom 
        PixelSearch, Px, Py, ScrollPosX, ScrollPosY, ScrollPosX, ScrollPosY, 0xf0f0f0, 1, Fast
        if ErrorLevel {
            ; Pixel not found -> Scroll bar at the bottom -> Label not found
            Break
        } else {
            ; Click the scrollbar to advance a page
            Click, %ScrollPosX%, %ScrollPosY%
        }
    } else {
        MsgBox The text was found at %FoundX%x%FoundY%.
    }
}
MsgBox, Cannot be found!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.