0

I'm trying to make something for our employees to use so that they dont have to alter the script itself to define hotkeys. This may only work for hotkeys which can be defined by a single character, but that's fine, as there are so many combinations that can be made with them, and they can be very easy to remember. The script would look only at 2 character AHK files (or 6 if you must include the extension) in the working directory. And the variables it would search for could be defined with RegEx so for the first hotkey, it would look like ^. and then second would look like .(?=.) Once a match is found, it would simply launch that matched file. Has something like this been done before? It seems so simple but I can't seem to find anything on it.

Edit: Elliot brought this to my attention: http://autohotkey.com/board/topic/60630-easy-editmanage-hotkeyshotstrings-plugin-ahk-l/

It's a neat script manager, and very useful, but it's not what I'm looking for.

I dont not want an additional interface. I want to be able to change the hotkeys by using the filename.

8
  • autohotkey.com/board/topic/… Commented Oct 30, 2015 at 22:02
  • Thanks Elliot but that's not what I'm looking for in this case. Please see my edit for more info. Commented Oct 30, 2015 at 22:54
  • Frankly, I don't really understand what you want to do. Why do you need multiple files and why do they have to be 2 chars long?? For managing different hotkey setups, I'd use iniread/iniwrite for configuration, maybe a gui for selection, and formostly the hotkey command ahkscript.org/docs/commands/Hotkey.htm which can assign hotkeys dynamically. Commented Oct 31, 2015 at 11:49
  • the files are script files. the file name has to be 2 characters long. i dont think you understand my question Commented Oct 31, 2015 at 20:15
  • True. Seems there is nothing we can do about it. Commented Oct 31, 2015 at 20:42

2 Answers 2

1
+100

Based on the answer of Forvin. Added the execution of the corresponding ahk script.

#Persistent
SetTimer, FindNewHotkeys, 2000
FindNewHotkeys:
    Loop, %A_ScriptDir%\*
    {
        RegExMatch(A_LoopFileName, "^(.)(.).ahk$", hk)

        If (hk)
        {
          Hotkey, ~%hk1% & ~%hk2%, HotkeyLabel
        }
    }
Return

HotkeyLabel:
  RegExMatch(A_ThisHotkey, "~(.) & ~(.)", hk)
  run, %hk1%%hk2%.ahk
Return
Sign up to request clarification or add additional context in comments.

2 Comments

This is awesome! Thank you so much!
I thought I would give the bounty to you and mark the other one as the answer but I guess it makes more sense to give you both.
1
#Persistent
SetTimer, FindNewHotkeys, 2000

FindNewHotkeys:
    Loop, %A_ScriptDir%\*
    {
        RegExMatch(A_LoopFileName, "^(.)(.).ahk$", hk)

        If (hk)
            Hotkey, ~%hk1% & ~%hk2%, HotkeyLabel
    }
Return

HotkeyLabel:
    MsgBox, A hotkey has been pressed!
Return

3 Comments

I can't seem to get it to work. I put the file in the same location as my .ahk file with the two letter filename (in this case I used GS). I started your script, tried the hotkeys and it did not display the messagebox
Then you must be doing soemthing wrong. Make sure the file doesn't have an extension. Also try to run the script as admin.
Oops. I didn't notice how the Regex was being used. I'm going to suggest a couple edits. I found another issue with the hotkeys lacking tildes in the front. Also, I am unsure how to launch the hotkey file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.