Thank you for this

Dec 28, 2014 at 5:32 PM
I wanted to thank you for this amazing piece of code you built.
I dont get how it doesnt get far more attention. Perhaphs you should post it in the AHK forums.

I made some tweaks I wanted to comment you just in case you see they fit your code:
  • In case the user wants to use capslock for writting caps, I made it so when pressing twice caps lock, will disable the GUI and be toggled, and pressing it once more will disable caps lock.
  • I changed the ESC hotkey (Cancel script running) to Control Shift F12, since escape is used in far too many programs, such as autocad, and many others.
  • I decreased the display size of the text in the function "CPDisplayTextOnScreen", because it was too big, an dwould flood the screen.
    I kept track of those changes because I would love to stay updated with your versions.
Here is the code I replaced:

After the line:
; Intercept the Up and Down actions to move through the commands in the listbox.
Gui, 1:Destroy  ; Close the GUI, but leave the script running.
SetCapslockState, On                ; Turn CapsLock off after it was pressed
Gui, 1:Destroy
This code too:
; Hotkey to launch the Command Picker window.
    if GetKeyState("CapsLock", "T")
    SetCapslockState, Off               ; Turn CapsLock off after it was pressed
    SetCapslockState, Off               ; Turn CapsLock off after it was pressed
After this lines, is where I replaced the "ESC UP" hotkey:
; Hotkey to reload the AHK Command Picker when it is executing a command.
; This can be used if one of the scripts is out of control and you need to kill it quickly.
And of course commented the line that was sending ESC:
;SendInput, {Esc}
Thanks again for this.
Dec 29, 2014 at 1:12 PM
Found another issue, when searching, space should separate search results:

For instance, say you have these two command names:

"Copy Paste Image"

When searching, and writting in the input box: "p i" should send you to the second one, but now it sends you to "Ping" as first result, the second one as second.
The first result should only happen if you write "pi" in my opinion.

is there a reason for that? If not, I will probably end up changing it to behave like described.
Dec 30, 2014 at 5:22 AM
Thanks @Armagedoom :) And posting about AHK Command Picker in the AHK Forums is a great idea!

To your questions:
  1. To enable/disable the capslock key you can simply use Shift+Caps Lock. I chose this rather than a double-capslock-click because I find that rarely do I ever actually want capslock on. Also, as you've probably noticed, if the app that has focus stops responding, hitting capslock often will not launch the AHK Command Picker GUI. You need to actually set focus to another app that is responding first. In that situation I often hit caplock a number of times before realizing that the AHK GUI isn't showing because the focused app is not responding. I didn't want to be toggling the capslock state in these cases.
  2. I chose to simply use the Escape key to cancel running scripts because I often found myself panicking when accidentally triggering the wrong scripts. For example, if I had my code editor in focus and triggered something that would start inserting or deleting text, or worse, start closing applications (without saving first!). In those "panic" situations where I need to kill the script NOW, I didn't want to have to try and remember what the specific key combination was (since it's not all too often that I kill scripts intentionally). So that was my main motivation; the other was that it's not very often that I trigger long-running scripts, or at least, that I trigger long-running scripts that are supposed to run in the background while I keep interacting with the PC myself. That may not be the case for other people though. I think the best option here would be to add the option to the Settings and let the user choose if they want to use Escape or Ctrl+Shift+F12 to stop running scripts. Thanks for the suggestion :)
  3. Yeah, I should probably add a Font Size setting for the Selected Command Window too and default it to be a bit smaller. Thanks!
  4. I looked at the "space" issue before. I had problems getting spaces to work properly with my Camer/Pascal case regex matching, so I ended up just stripping all spaces out of the command names when processing them. You can see this around line 542 in AHKCommandPicker.ahk:
; Strip any spaces out of the command name, as they just get in the way of the camel case matching.
StringReplace, commandLine, commandLine, %A_Space%, , All
This is something that I should revisit though. Being a programmer I'm accustom to always writing things in camel case and not using spaces, but lots of other people aren't. If you can figure out the changes to make for this to happen, I'm totally willing to make the change :)

I also notice there that I'm running the regex on every command every time a character is typed into the command box. Eek. I should probably just run it once on every command the first time the GUI is launched and cache the results. This might potentially help the other known issue of command parameters not showing up properly when you type too fast.

Thanks for all the great feedback!
Dec 30, 2014 at 10:58 PM
Edited Dec 30, 2014 at 11:49 PM
@Deadlydog, Im very happy both to see that you liked my suggestions and that you are active on this amazing piece of software.

Posting it into AHK forums:

Yes, I saw a lot of really less elaborate and by far less useful scripts get much attention (and exposure), and then found yours by coincidence with no comments and very difficult to find! Its unfair!!


Sounds fair, I just didn't think of pressing "shift+caps". Now that I know of it, it will be easy to get adapted to your version if you update.


I totally agree and I like more the "escape" key, but I found that somehow having that hotkey was preventing escape to work in other applications.
Also, I was already using "Escape" hotkey for many other programs, so for making my hotkey work along with AHKCommandPicker, I had to embedd my current ESC hotkey into your script, but its so clean and organized that I just didnt want to mix it up... :)
I actually would rather have ESC quit the script as you suggest, but that would mean I would need to add my "ESC" into your script, and I rather keep them clean and switch to !F12 or other.
Please note that I added "ESC" hotkey for the GUI, so it exits when pressed, after the line "Intercept the Up and Down actions to move through the commands in the listbox.". More details about this in my first post.


And last, but not least, I was very happy and encouraged to know you are around... so studied, found and fixed the space issue.
Now, if you have two named commands, such as:

-My Big Dog
-Me Yawning

If the user searches for "my" both of them will appear. But if he searches for "m y" it will only match the second one! :D
It works like charm now.
And it was very important for me since all my commands are automatically created and "named commands" so they are easier to see and find etc... (I do this with my IDE)


A possible (and last) improvement could be to match unorganiced camel, so when the user searches for "Big" it would yield results in the previous examples.
This functionality would ease up new users to begin with your GUI, since just by typing "speakers" or "mute" or alike, they would be able to find the results, without even knowing of the existence of those commands.

Here is the code lines modified for the space to work:

Arround line 820, here are the new lines embedded with your code:
    ; Otherwise the character doesn't match the current word.

        while (character = " ")
            character := SubStr(searchString, searchCharacterIndex, 1)
        ; See if this character matches the start of the next word.
        return CPLetterMatchesPartOfCurrentWordOrBeginningOfNextWord(searchString, searchStringLength, searchCharacterIndex, wordArray, numberOfWordsInArray, wordIndex + 1, 1)
And of course I had to comment the "stripping away" of the spaces from the user search, around line 763:
CPCommandIsPossibleCamelCaseMatch(searchText, camelCaseWordsInCommandLine)
    ; Strip any spaces out of the user's string, as they just get in the way of the camel case matching.
    ;StringReplace, searchText, searchText, %A_Space%, , All
Thanks again for this code!

I already embedded a keylogger to this script, and In the future I would like to make the script be able to "guess", "suggest" or "learn" from what the user does. Already got a "window activation detector" which hooks to windows and keeps track of what commands you use in each window, so I don't think it is very far fetched to think about "tracking and suggesting" actions for the user depending on the active window and the users history.

Specially given how amazingly arranged are your functions (I learned a LOT from you), It seems easy to just automatically include some lines after each "AddNamedCommand" to keep track of the commands executed...

I will keep working with it and If find out more interesting ideas will happily report around. It might be some months, but I'll definitely be back.

Best regards from Spain, happy new year!


PD: Just found the spaces script its not perfect yet:

When you have two named commands such as:

"My Big Dog"
"Meta Yoyo"

And you write down the full word followed by space:
"My B" It will yield no results.

Will look into that the following days
Dec 31, 2014 at 10:40 AM
Just fixed it, here are the new code changes from scrap (dont consider the code in the previous post):

around Line 765, comment:
    ; Strip any spaces out of the user's string, as they just get in the way of the camel case matching.
    ;StringReplace, searchText, searchText, %A_Space%, , All
Around line 800, here is the new code embedded in a couple of lines pre and post of your code:
    ; Get the character at the specified character index
    character := SubStr(searchString, searchCharacterIndex, 1)
    while (character = " ")
        character := SubStr(searchString, searchCharacterIndex, 1)
        wordCharacterIndex = 1
    ; If the character matches in this word, then keep going down this path.
    if (character = SubStr(wordArray%wordIndex%, wordCharacterIndex, 1))
Jan 2, 2015 at 9:49 AM
Edited Jan 2, 2015 at 9:50 AM
Hope you are doing great, here is another question :)

The script Im using has some hooks for detecting window activations. And those hooks will stop working after AHKCommandPicker GUI closes.
So I searched for every instance of "GUI 1:Destroy" in "AHKCommandPicker.ahk" and added a function call to restart the hooks.
Here is the example of the hooks Im talking about, but I think this would include any other "permanent" script:
Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Is there a cleaner way to do this rather than adding "call_hooks_again()" after each "GUI 1:destroy"?
Jan 2, 2015 at 10:47 PM
So I tried making the code changes you supplied, but still did not get proper detection when using spaces. Maybe I missed something or you forgot to post something?

For your call_hooks_again() function, where are you hooking it up to begin with? What triggers the code to be ran? If it's just some code that needs to be ran once to initialize the hooks, you should be able to add it in with your AddCommand() functions, so long as it doesn't involve a hotkey (e.g. SomeKey::SomeCode). That way it shouldn't "stop running" until the script is closed or reloaded.
Jan 3, 2015 at 9:35 AM
Sorry for that, I will make a clean-copy of "AHKCommandPicker.ahk" and clean edit all the things we discussed and send it to you.
As you can probably guess Im just a hobby programmer so I dont know well codeplex or other IDE's, I just know how to use github.
Thank you for your support.
Apr 29, 2016 at 11:58 PM
First of all thank you for such an awesome program. And I am very sorry to bother you with that, but I encounter a problem while running it that I cannot solve.

Line Text: For index, value in parameters
Error: This line does not contain a recognized action

Maybe you could help me with that.

Thank you,
May 3, 2016 at 7:05 AM
@novice33 The text "For index, value in parameters" appears on line 877 of the AHKCommandPicker.ahk file, but should be commented out.
    ;~ ; Example of how to loop through the parameters
    ;~ For index, value in parameters
        ;~ MsgBox % "Item " index " is '" value "'"
Were you making manual changes to that file and accidentally uncommented those lines?

Also, these types of questions would be better to post in their own new issue, rather than tagging onto this existing discussion. If you're still having the problem, please start a new Issue for it. Thanks.