Output list of all hotkeys used in ahk Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MrShhh
Posts: 8
Joined: 10 Jun 2016, 13:29

Output list of all hotkeys used in ahk

21 Jun 2017, 08:18

Hi,

I'm using a lot of hotkeys in my ahk. That many that I'm having trouble remembering all of them and what they do.
I'm looking for yet another hotkey that will list all the hotkeys and their function used in the .ahk. I'm aware of the "Hotkeys and their Methods" feature under "View" in the AHK application. But the problem is that this doesn't show their function.
"Hotkeys and their Methods" look like this:
Type Off? Level Running Name
-------------------------------------------------------------------
reg !1
reg ^+!1
reg ^+2
reg !2
reg !3
....

In my .ahk I include a small function summary/description after the hotkey. IE:

!8:: ;Add /24 ip-address to _VLAN_01_untagged
^numpad2:: ;Firefox url

I might be looking for a script that can read the ahk file, search for all the hotkeys (maybe it can search the :: after the hotkey) and output that entire line associated with each hotkey in a msgbox or something.
Or maybe someone has a better idea? Can someone help me out?

Kind regards.
robmar-zl
Posts: 24
Joined: 05 Feb 2015, 04:57

Re: Output list of all hotkeys used in ahk

21 Jun 2017, 08:33

"Hotkey Help - Display Active AHK Hotkeys and Hotstrings" could be what you are searching for.
https://autohotkey.com/board/topic/9388 ... otstrings/

Try the sample an press Win+F1 for the Hotkey-Overview-Window

I think you only have to change to comments you already have in your code

Greetings
Rob
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Output list of all hotkeys used in ahk

21 Jun 2017, 09:22

Code: Select all

; autoexecute section:
Gui, -Caption
Gui, Add, ListBox, vMyListBox r50 w200
Loop, Read, %A_ScriptFullpath%
{
	If !InStr(A_LoopReadLine, ":: `;")
		continue	
	StringReplace, ReadLine, A_LoopReadLine, %A_Space%`;, %A_Tab%
	GuiControl,, MyListBox, %ReadLine%
}
; ...
return  ; end of autoexecute section

; Hotkey to show|hide the GUI:
F2:: ; Gui hotkeys
If (toggle := !toggle)
    Gui, Show, x0 y0
else
    Gui, cancel
return
MrShhh
Posts: 8
Joined: 10 Jun 2016, 13:29

Re: Output list of all hotkeys used in ahk

21 Jun 2017, 10:20

robmar-zl wrote:"Hotkey Help - Display Active AHK Hotkeys and Hotstrings" could be what you are searching for.
https://autohotkey.com/board/topic/9388 ... otstrings/

Try the sample an press Win+F1 for the Hotkey-Overview-Window

I think you only have to change to comments you already have in your code

Greetings
Rob
Thanks Rob, That one is a bit too complicated for me though! :roll: :lol:
GEV wrote:

Code: Select all

; autoexecute section:
Gui, -Caption
Gui, Add, ListBox, vMyListBox r50 w200
Loop, Read, %A_ScriptFullpath%
{
 If !InStr(A_LoopReadLine, ":: `;")
 continue 
 StringReplace, ReadLine, A_LoopReadLine, %A_Space%`;, %A_Tab%
 GuiControl,, MyListBox, %ReadLine%
}
; ...
return ; end of autoexecute section

; Hotkey to show|hide the GUI:
F2:: ; Gui hotkeys
If (toggle := !toggle)
 Gui, Show, x0 y0
else
 Gui, cancel
return
This is perfect! It shows the lines with all the hotkeys and the comments.
One thing though: I cant seem to get the pop up window wider than 100 pixels. So it can't show all the comments in full.
Gui, Show, x0 y0 w200 does make the window 200 pixels wide but the actual field with text stays the same about 100 pixels the rest is grayed out.
Gui, Show, x0 y0 Maximize wields the same results but now the grayed out part is maximized. AutoSize doesnt change it at all. Do you maybe have a solution for that part?

Thanks so much already, truly love this community.
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Output list of all hotkeys used in ahk

21 Jun 2017, 10:32

To change the width of the ListBox, change the last parameter of the command:
Gui, Add, ListBox, vMyListBox r50 w200
to e.g. w300
robertcollier4
Posts: 33
Joined: 09 Apr 2016, 22:14

Re: Output list of all hotkeys used in ahk

21 Jun 2017, 12:49

https://www.autohotkey.com/docs/command ... otkeys.htm

Code: Select all

ListHotkeys
Displays the hotkeys in use by the current script, whether their subroutines are currently running, and whether or not they use the keyboard or mouse hook.
This command is equivalent to selecting the View->Hotkeys menu item in the main window.
Last edited by robertcollier4 on 22 Jun 2017, 00:17, edited 1 time in total.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Output list of all hotkeys used in ahk  Topic is solved

21 Jun 2017, 13:35

MrShhh wrote:
robmar-zl wrote:"Hotkey Help - Display Active AHK Hotkeys and Hotstrings" could be what you are searching for.
https://autohotkey.com/board/topic/9388 ... otstrings/

Try the sample an press Win+F1 for the Hotkey-Overview-Window

I think you only have to change to comments you already have in your code

Greetings
Rob
Thanks Rob, That one is a bit too complicated for me though! :roll: :lol:
Hotkey Help does exactly what you describe.

Below is a current link:
https://autohotkey.com/boards/viewtopic.php?f=6&t=96

The code might be complicated but its use is simple. Just run the script and press Win+F1 to get a list of all AHK scripts running and the hotkeys in those scripts along with the comment on the same line as the hotkey. The beauty of Hotkey Help is that it is an independent script that finds the hotkeys of all other running scripts. If you have 20 scripts running it will list the hotkeys in all of them without having to put code in each script.

If you want something more lightweight for only the script that is doing the display, you can try this function that basically does what GEV is doing in a little more robust way and also expands the modifier keys symbols to words.

Code: Select all

; autoexecute section:
Gui, -Caption
Gui, Add, ListView,, HOTKEY|COMMENT
for Index, Element in Hotkeys(Hotkeys)
    LV_Add("",Element.Hotkey, Element.Comment)
LV_ModifyCol()

; Hotkey to show|hide the GUI:
^#F12:: ; Gui hotkeys
    If (Toggle := !Toggle)
     Gui, Show, x0 y0
    else
     Gui, Cancel
return

; Read Hotkeys from Script File
Hotkeys(ByRef Hotkeys)
{
    FileRead, Script, %A_ScriptFullPath%
    Script :=  RegExReplace(Script, "ms`a)^\s*/\*.*?^\s*\*/\s*|^\s*\(.*?^\s*\)\s*")
    Hotkeys := {}
    Loop, Parse, Script, `n, `r
        if RegExMatch(A_LoopField,"^\s*(.*):`:.*`;\s*(.*)",Match)
        {
            if !RegExMatch(Match1,"(Shift|Alt|Ctrl|Win)")
            {
                StringReplace, Match1, Match1, +, Shift+
                StringReplace, Match1, Match1, <^>!, AltGr+
                StringReplace, Match1, Match1, <, Left, All
                StringReplace, Match1, Match1, >, Right, All 
                StringReplace, Match1, Match1, !, Alt+
                StringReplace, Match1, Match1, ^, Ctrl+
                StringReplace, Match1, Match1, #, Win+
            }
            Hotkeys.Push({"Hotkey":Match1, "Comment":Match2})
        }
    return Hotkeys
}
It also uses a ListView instead of a ListBox which auto sizes and aligns things in columns better.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
MrShhh
Posts: 8
Joined: 10 Jun 2016, 13:29

Re: Output list of all hotkeys used in ahk

05 Jul 2017, 14:54

Thank you all very much for the responses. Its working great! This is what my script looks like now:

Code: Select all

Hotkeys(ByRef Hotkeys)
{
if (A_ComputerName = "Computer") {
    FileRead, Script, %A_ScriptFullPath%
}
If (A_ComputerName = "Laptop") {
    FileRead, Script, %A_ScriptFullPath%
}
    Script :=  RegExReplace(Script, "ms`a)^\s*/\*.*?^\s*\*/\s*|^\s*\(.*?^\s*\)\s*")
    Hotkeys := {}
    Loop, Parse, Script, `n, `r
        if RegExMatch(A_LoopField,"^\s*(.*):`:.*`;\s*(.*)",Match)
        {
            if !RegExMatch(Match1,"(Shift|Alt|Ctrl|Win)")
            {
                StringReplace, Match1, Match1, +, Shift+
                StringReplace, Match1, Match1, <^>!, AltGr+
                StringReplace, Match1, Match1, <, Left, All
                StringReplace, Match1, Match1, >, Right, All 
                StringReplace, Match1, Match1, !, Alt+
                StringReplace, Match1, Match1, ^, Ctrl+
                StringReplace, Match1, Match1, #, Win+
            }
            Hotkeys.Push({"Hotkey":Match1, "Comment":Match2})
        }
    return Hotkeys
}
I then used the option to have the Listview window options under a hotkey as well because I'm now using more then one ListViews in the same script and the set windows sizes kept interfering with each other. The feature "Gui, destroy" is implemented to make it 'forget' the window sizes as soon as the script is completed. That code looks like this:

Code: Select all

F1:: ; Gui Hotkeys
Gui, Add, ListView, h700 w500, HOTKEY|COMMENT
LV_ModifyCol(1, 125)
LV_ModifyCol(2, 375)
for Index, Element in Hotkeys(Hotkeys)
    LV_Add("",Element.Hotkey, Element.Comment)
    If (Toggle := !Toggle)
     Gui, Show, x0 y0
    else
     Gui, Destroy
return
FanaticGuru wrote: It also uses a ListView instead of a ListBox which auto sizes and aligns things in columns better.
I couldn't get the auto size to work but having a fixed window size works as well. Thanks for pointing out ListView, I like it a lot!
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Output list of all hotkeys used in ahk

05 Jul 2017, 17:14

Code: Select all

if (A_ComputerName = "Computer") {
    FileRead, Script, %A_ScriptFullPath%
}
If (A_ComputerName = "Laptop") {
    FileRead, Script, %A_ScriptFullPath%
}
I don't really understand this part. Regardless of A_ComputerName the script is going to do the exact same thing. I guess if A_ComputerName is not either one of those the function will return nothing but there are more straight forward ways of having the script return nothing.

As for multiple GUI, you just use names for the GUI which is easy to do with the Default option.

Code: Select all

; autoexecute section:
Gui, ThisGui:Default
Gui, -Caption
Gui, Add, ListView,, HOTKEY|COMMENT
for Index, Element in Hotkeys(Hotkeys)
    LV_Add("",Element.Hotkey, Element.Comment)
LV_ModifyCol()

Gui, ThatGui:Default
Gui, -Caption
Gui, Add, ListView,, HOTKEY|COMMENT
for Index, Element in Hotkeys(Hotkeys)
    LV_Add("",Element.Hotkey, Element.Comment)
LV_ModifyCol()

; Hotkey to show|hide the GUI:
^#F12:: ; Gui hotkeys, ThisGUI
    If (Toggle1 := !Toggle1)
     Gui, ThisGui:Show, x0 y0
    else
     Gui, ThisGui:Cancel
return

^#F11:: ; Gui hotkeys, ThatGUI
    If (Toggle2 := !Toggle2)
     Gui, ThatGui:Show, x200 y200
    else
     Gui, ThatGui:Cancel
return

; Read Hotkeys from Script File
Hotkeys(ByRef Hotkeys)
{
    FileRead, Script, %A_ScriptFullPath%
    Script :=  RegExReplace(Script, "ms`a)^\s*/\*.*?^\s*\*/\s*|^\s*\(.*?^\s*\)\s*")
    Hotkeys := {}
    Loop, Parse, Script, `n, `r
        if RegExMatch(A_LoopField,"^\s*(.*):`:.*`;\s*(.*)",Match)
        {
            if !RegExMatch(Match1,"(Shift|Alt|Ctrl|Win)")
            {
                StringReplace, Match1, Match1, +, Shift+
                StringReplace, Match1, Match1, <^>!, AltGr+
                StringReplace, Match1, Match1, <, Left, All
                StringReplace, Match1, Match1, >, Right, All 
                StringReplace, Match1, Match1, !, Alt+
                StringReplace, Match1, Match1, ^, Ctrl+
                StringReplace, Match1, Match1, #, Win+
            }
            Hotkeys.Push({"Hotkey":Match1, "Comment":Match2})
        }
    return Hotkeys
}
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
MrShhh
Posts: 8
Joined: 10 Jun 2016, 13:29

Re: Output list of all hotkeys used in ahk

06 Jul 2017, 17:31

FanaticGuru wrote:

Code: Select all

if (A_ComputerName = "Computer") {
    FileRead, Script, %A_ScriptFullPath%
}
If (A_ComputerName = "Laptop") {
    FileRead, Script, %A_ScriptFullPath%
}
I don't really understand this part. Regardless of A_ComputerName the script is going to do the exact same thing. I guess if A_ComputerName is not either one of those the function will return nothing but there are more straight forward ways of having the script return nothing.
I use the same script on two different computers, I was under the assumption I had to replace %A_ScriptFullPath% with the full path tot the script. Your comment made me realise this is a feature on its own... ... ... ...
As for multiple GUI, you just use names for the GUI which is easy to do with the Default option.

Code: Select all

; autoexecute section:
Gui, ThisGui:Default
Gui, -Caption
Gui, Add, ListView,, HOTKEY|COMMENT
for Index, Element in Hotkeys(Hotkeys)
    LV_Add("",Element.Hotkey, Element.Comment)
LV_ModifyCol()

Gui, ThatGui:Default
Gui, -Caption
Gui, Add, ListView,, HOTKEY|COMMENT
for Index, Element in Hotkeys(Hotkeys)
    LV_Add("",Element.Hotkey, Element.Comment)
LV_ModifyCol()

; Hotkey to show|hide the GUI:
^#F12:: ; Gui hotkeys, ThisGUI
    If (Toggle1 := !Toggle1)
     Gui, ThisGui:Show, x0 y0
    else
     Gui, ThisGui:Cancel
return

^#F11:: ; Gui hotkeys, ThatGUI
    If (Toggle2 := !Toggle2)
     Gui, ThatGui:Show, x200 y200
    else
     Gui, ThatGui:Cancel
return

; Read Hotkeys from Script File
Hotkeys(ByRef Hotkeys)
{
    FileRead, Script, %A_ScriptFullPath%
    Script :=  RegExReplace(Script, "ms`a)^\s*/\*.*?^\s*\*/\s*|^\s*\(.*?^\s*\)\s*")
    Hotkeys := {}
    Loop, Parse, Script, `n, `r
        if RegExMatch(A_LoopField,"^\s*(.*):`:.*`;\s*(.*)",Match)
        {
            if !RegExMatch(Match1,"(Shift|Alt|Ctrl|Win)")
            {
                StringReplace, Match1, Match1, +, Shift+
                StringReplace, Match1, Match1, <^>!, AltGr+
                StringReplace, Match1, Match1, <, Left, All
                StringReplace, Match1, Match1, >, Right, All 
                StringReplace, Match1, Match1, !, Alt+
                StringReplace, Match1, Match1, ^, Ctrl+
                StringReplace, Match1, Match1, #, Win+
            }
            Hotkeys.Push({"Hotkey":Match1, "Comment":Match2})
        }
    return Hotkeys
}
FG
I have tried this and as you can see the script does have a name (and the second one a different name), however when loading one after the other the second one keeps the settings from the first one. Gui destroy solves this.

Mr. Shhh

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, Spawnova and 342 guests