In script, selecting multiple .ahk files and loading them

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ssapicek
Posts: 4
Joined: 09 May 2022, 07:40

In script, selecting multiple .ahk files and loading them

Post by ssapicek » 09 May 2022, 07:56

Hi all,

I’m trying but cannot figure out, so I beg for help … I use AKH mostly for hotstring. I work on several projects, each of them having its own set of hotstrings in a separate file, therefore a project = an .ahk file with hotstrings. However, the longer I use this method, the more my hotstrings are overlapping and I end up wanting several hotstrings for one key (like “BTW” = back to work, by the way, behind the heels. This whole system is not working for me, as I end up making really obscure keys.

As I never work on all projects at the same time, I’m trying to create a function that would show the list of projects (ok, it may be a list of .ahk files), I would multiselect some of them, and AHK would purge all hotstrings and load only those files selected.
Can anybody help, perhaps charting the code a bit?

Thanks a lot!
Petr

User avatar
mikeyww
Posts: 26861
Joined: 09 Sep 2014, 18:38

Re: In script, selecting multiple .ahk files and loading them

Post by mikeyww » 09 May 2022, 09:04

Welcome to this AutoHotkey forum!

You could just use one script, with #If, and set conditions by variables or according to which windows are active.

Code: Select all

#If WinActive("ahk_exe notepad.exe")
::btw::by the way
#If
Or:

Code: Select all

GroupAdd, proj1, ahk_exe notepad.exe
GroupAdd, proj1, ahk_exe chrome.exe

#If WinActive("ahk_group proj1")
::btw::by the way
#If
Or:

Code: Select all

F3::proj = 1

#If (proj = 1)
::btw::by the way
#If

ssapicek
Posts: 4
Joined: 09 May 2022, 07:40

Re: In script, selecting multiple .ahk files and loading them

Post by ssapicek » 02 Dec 2022, 07:53

Thanks a lot Mikey!

I’m so sorry for so late response as I had some troubles signing in the forum.
Back to the question:

The thing is that this will not work for me. Suppose you are working for client “A” (e.g. you need hot hotstring set for A) IN ALL OF YOUR WINDOWS (Word, Excel, AutoCAD, mail, chrome…). Then B calls, you work for B (you need partially different hotstrings – same keys, different values). You open a new Word, Excel, AutoCAD etc. for B and – what I would like most – you hit some AHK hotkey, AHK opens a multiple selection in list with all .akh files from a hard-set directory, you select the files that you want to load and AHK loads them.

This solution is pretty fast to use and versatile.
The thing is that I have no clue how to use multiple selection in list, get files from directory, handle multiple selection results and load just those files.

If you can help me with that, I would be happy :-)

Thanks a lot,
Petr

User avatar
mikeyww
Posts: 26861
Joined: 09 Sep 2014, 18:38

Re: In script, selecting multiple .ahk files and loading them

Post by mikeyww » 02 Dec 2022, 08:26

You could use a Gui with a dropdown list to select a client. This could set a variable that is then used in #If as a context.

Code: Select all

Gui, +AlwaysOnTop
Gui, Font, s10
Gui, Add, DropDownList, w230 vclient gChange, Client A|Client B
Gui, Show, NoActivate, Clients

#If (client = "Client A")
::btw::by the way

#If (client = "Client B")
::btw::Not
#If

Change:
Gui, Submit, NoHide
Return
There are alternatives for how to use the "Change" subroutine: use a database, run a script, etc. Any number of possibilities.

If you want to put code into separate files, you can #Include those files in your main script.

ssapicek
Posts: 4
Joined: 09 May 2022, 07:40

Re: In script, selecting multiple .ahk files and loading them

Post by ssapicek » 06 Dec 2022, 03:47

Good, that should help !
Thanks a lot!!!

Petr

ssapicek
Posts: 4
Joined: 09 May 2022, 07:40

Re: In script, selecting multiple .ahk files and loading them

Post by ssapicek » 18 Jan 2023, 12:46

Hi Mickey,
I stared using the script you suggested, updated it with my hotkeys (2000 of them in total) and I found I need to tweak it a bit, which I’, not able to. Would you please help me?

1) By choosing other client I need to unload current set of hotkeys, before loading hotkeys for the selected client. How do I unload only hotkeys, keeping the rest of the script intact?
2) A set of hotkeys is shared – these I need to reload. That I suppose is easy, I’ll just #include a constant file in every branch of #if

Thanks a lot,
Petr

User avatar
mikeyww
Posts: 26861
Joined: 09 Sep 2014, 18:38

Re: In script, selecting multiple .ahk files and loading them

Post by mikeyww » 18 Jan 2023, 12:58

One script can be used. As demonstrated in this thread, the #If directive defines a context for hotkeys or hotstrings to be active. Other code, and hotkeys & hotstrings not governed by a context definition, would apply in any context.

Code: Select all

#Requires AutoHotkey v1.1.33
n := 1
Loop {
 Send % A_Index " "
 Sleep 1000
}

F2:: Send all `
F3::
Send a `
n++
Return

#If (n = 2)
F3::
Send b `
n++
Return

#If (n > 2)
F3::
Send c `
n++
Return
#If
Explained: Variant hotkeys

Post Reply

Return to “Ask for Help (v1)”