Using AutoHotkey to click a button in a window

I want to make an AutoHotkey script to change the font in the PuTTY SSH client. (I prefer a small font for high density information, but when I show something to a colleague, they should be able to see it clearly.) I got this far:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. #SingleInstance force ; Lets the RunMe plugin for Notepad++ reload the script with Shift-F5. #IfWinActive ahk_class PuTTY ; If PuTTY is active ^+1:: ; and Ctrl-Shift-1 is pressed { Send !{Space} ; Alt-Space to open the system menu Send g ; open Change Settings Send !g ; select the Category menu Send w ; select the Window category Send {Right} ; expand the category Send a ; select the Appearance subcategory ControlClick, ClassNN Button8, ahk_class PuTTYConfigBox, , Left, 1 } #IfWinActive 

When starting from the PuTTY terminal window, everything via the "Send" button moves to the PuTTY menu, as expected, bringing me to the "Appearance" subcategory. At this point, I want to click the "Change ..." button to install the font. I would prefer not to send a bunch of tabs or specify a screen coordinate to select a button; as it seems kludgey and will probably break with future updates. However, I cannot get ControlClick to work. The line I used above is my best premise after several hours of research, and I don’t understand why it does not do anything.

The Spy Spy window is displayed here when I am cruising over the button:

 >>>>>>>>>>( Window Title & Class )<<<<<<<<<<< PuTTY Reconfiguration ahk_class PuTTYConfigBox >>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<< On Screen: 1051, 207 (less often used) In Active Window: 432, 202 >>>>>>>>>( Now Under Mouse Cursor )<<<<<<<< ClassNN: Button8 Text: Change... Color: 0xF0F0F0 (Blue=F0 Green=F0 Red=F0) >>>>>>>>>>( Active Window Position )<<<<<<<<<< left: 619 top: 5 width: 456 height: 438 >>>>>>>>>>>( Status Bar Text )<<<<<<<<<< >>>>>>>>>>>( Visible Window Text )<<<<<<<<<<< &Apply &Cancel Cate&gory: Cursor appearance: B&lock &Underline &Vertical line Cursor &blinks Adjust the use of the cursor Fo&nt used in the terminal window Font: Lucida Console, 24-point Change... Allow selection of variable-pitch fonts Font &quality: Antialiased Non-Antialiased ClearType Default Font settings Hide mouse &pointer when typing in window Adjust the use of the mouse pointer Gap b&etween text and window edge: &Sunken-edge border (slightly thicker) Adjust the window border >>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<< >>>>( TitleMatchMode=slow Visible Text )<<<< 1 >>>>( TitleMatchMode=slow Hidden Text )<<<< 

Thanks for your help.

+4
source share
1 answer

I needed to do two things to get this to work.

Firstly, including the word "ClassNN" in the first ControlClick parameter was incorrect, despite several examples, I found that I used this. The parameter can be the button text (Change ...), the beginning of the text (Change) or its ClassNN (Button8), but not "ClassNN Button8". Everything after that is unnecessary and works fine with default values. Currently, I just use "ControlClick, Change ..." as the whole line, although it would be wiser to specify WinTitle explicitly (either "PuTTY Reconfiguration" or "ahk_class PuTTYConfigBox" works).

Secondly, as MCL pointed out, I needed "WinWait, PuTTY Reconfiguration" before the ControlClick command. I do not quite understand why, but it works.

Here is my last working code, with F9, going to ProggyCleanTT 12 points, and F10 will switch to Lucida Console 20 point:

 #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. #SingleInstance force ; Lets the RunMe plugin for Notepad++ reload the script with Shift-F5. ; This will only work for PuTTY sessions in which, under Window/Behavior, you have checked ; "System menu appears on ALT-Space". Don't forget to save the change. #IfWinActive ahk_class PuTTY F9::ChangePuttyFont("ProggyCleanTT", 12) F10::ChangePuttyFont("Lucida Console", 20) #IfWinActive ChangePuttyFont(font, size) { Send !{Space} ; open the system menu Send g ; open Change Settings Send !g ; select the Category menu Send Window ; select the Window category Send {Right} ; expand the category Send Appearance ; select the Appearance subcategory WinWait, PuTTY Reconfiguration ; This is necessary for some reason ControlClick, Change... ; click the "Change..." button (under Font Settings) Send %font% ; select font Send !s ; select size field Send %size% ; select size Send {Enter} ; close font window SEND !a ; close settings window return } 

It does strange things if you do not wait a minute between pressing a hot key and an additional input, and probably it can have more reliable navigation, but it works.

+2
source

Source: https://habr.com/ru/post/1502521/


All Articles