AutoHotkey hotkey list display

Ive written a script that contains many hot keys (the general structure is given below). I would like to create another one that, when pressed, displays a list of all the hot keys and their corresponding descriptions, which the script contains in a good, formatted table.

Formatting and display are negligible since AutoHotkeys output is message-limited, but possible. More problematic is getting hotkeys and related descriptions.

All hot keys invoke the same function with different arguments. I thought about adding a variable to the function, so depending on the value, the function either performs a normal function when it is started with ordinary hot keys, or builds a line or something when it starts with a hot key of a special display.

I can not find a way to programmatically access the hotkeys script. I checked the documents and it does not seem that there are any A_ variables that can be used for this purpose, nor does the Hotkey well (it can be used to check if a hotkey exists, but iterates through countless combinations at best case is tiring).

Failed Attempts:

  • I tried using the Elliots clause to parse the script itself (replacing the path with% A_ScriptFullPath%, and although it works for a raw script, this does not happen when the script is compiled
  • I tried to assign the entire script hotkey section to a variable as a continuation section, and then parse the variable and create hotkeys using the Hotkey . This worked well until the last part, because the Hotkey cannot accept arbitrary commands as a destination and requires existing labels.
  • The ListHotkeys command ListHotkeys not applicable because it displays only keyboard shortcuts as plain text in the control window.

Does anyone know how I can display a list of hot keys and their corresponding arguments or comments?


Sample script:
 SomeFunc(foobar) { MsgBox %foobar% } !^#A::SomeFunc("a") ; blah ^+NumpadMult::SomeFunc("c") ; blivet ^+!#`::SomeFunc("b") ; baz ^#Space::SomeFunc("d") ; ermahgerd … 

An example of the desired "outputs":

 C+A+ W+ A a | C+ S+ NumpadMult b ------------------+---------------------- C+A+S+W+ ` c | C+ W+ Space d 

or

 Ctrl Alt Shift Win Key Action ----------------------------------------- Γ— Γ— Γ— A blah Γ— Γ— NumpadMult baz Γ— Γ— Γ— Γ— ` blivet Γ— Γ— Space ermahgerd etc. 
+1
source share
2 answers

I have found a solution. This is not ideal (or ideal), and I hope that in the future the correct built-in method will be available, but it works well (enough) for raw and compiled scripts.

What I did was use the FileInstall command, which tells the compiler to add the file to the executable (and extract it when it starts).

Unfortunately, the FileInstall command FileInstall not allow the use of variables for the source file, so I can’t just include the script itself ( FileInstall, %A_ScriptFullPath%, %A_Temp%\%A_ScriptName%, 1 ).

As work, I ended up extracting all the desired hotkeys to the second file, which I then analyze as suggested by Elliot, then delete and #Include at the end of my script (it should be at the end, since the hotkeys will complete the autoexecute section).

 ;;;;; Test.ahk ;;;;; ; Add hotkey file to executable and extract to Temp directory at runtime FileInstall, Hotkeys.ahk, %A_Temp%\Hotkeys.ahk, 1 Loop { ;Read a line from the extracted hotkey script and quit if error FileReadLine, line, %A_Temp%\Hotkeys.ahk, %A_Index% if ErrorLevel break ;Trim whitespace line=%line% ; Parse the line as in Elliot's answer, but with tweaks as necessary ParseHotkey(line) … } FileDelete, %A_Temp%\Hotkeys.ahk ; Delete the extracted script DisplayHotkeys() ; I ended up bulding and using a GUI instead #Include, Hotkeys.ahk ; It is included at compile-time, so no A_Temp ;;;;; Hotkeys.ahk ;;;;; z::MsgBox foo y::MsgBox bar 
0
source

The only thing I can think of is to read each line of your script individually and analyze it. This code reads your script (script.ahk) one line at a time and parses it. That should get you started. In addition, you can parse the string to check modifiers as well.

 Loop { FileReadLine, line, C:\script.ahk, %A_Index% if ErrorLevel break If Instr(line, "::") { StringSplit, linearray, line, ::, key := linearray1 StringSplit, commandarray, linearray3, `; action := commandarray2 hotkeyline := "key: " . key . "`tAction: " . action final .= hotkeyline . "`r" } } msgbox % final return 
+1
source

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


All Articles