0
votes

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.

2
Thanks Elliot but that's not what I'm looking for in this case. Please see my edit for more info.shaunxer
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.phil294
the files are script files. the file name has to be 2 characters long. i dont think you understand my questionshaunxer
True. Seems there is nothing we can do about it.phil294

2 Answers

1
votes
#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
1
votes

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