How do YOU start most of your AHK scripts?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scr1pter
Posts: 432
Joined: 06 Aug 2017, 08:21
Location: Germany

How do YOU start most of your AHK scripts?

14 Jun 2018, 08:56

Not a gaming related question!

Hi guys,

I've been working with AHK for a while and I always get fascinated by its (almost) limitless possibilities.

In many cases I create bigger scripts which contain single scripts.
The single scripts get activated by keystrokes (e.g. Ctrl+Shift+F1 till Ctrl+Shift+F12).
Inside of my Logitech "Gaming" ;) Software, I assign the keystrokes/key combinations to my G keys.
Then I just compile the AHK script and let it run in background.

When my target app is active and the profile has been loaded (Notepad++, Excel, some game etc.),
pressing the specific G key always works perfectly.

Now I'm thinking that in some case it might be useful to create single AHK scripts
without any keystroke/keycombination.
Then I don't assign any key to the G key, but simply the AHK/exe file (as a link).
The result is the same, but I wonder if method 2 has any disadvantages like cpu performance etc.
(Because a new process gets created).

Method 1 as code would be:

Code: Select all

^+F1::
line = 1
while ErrorLevel != 1
{
  FileReadLine, Clipboard, %A_ScriptDir%\Conversion(001).txt, %line%
  Send ^v
  Sleep, 5
  Send {Tab}
  Sleep, 5
  line++
}
return

^+F2::
WinGetTitle, title, A ; Get current window title
if title contains .txt ; if it contains .txt
{
  title := StrReplace(title, " - Editor") ; replace " - Editor" by nothing
}
Clipboard = WinGetTitle%title% ; Clipboard = WinGetTitle%title% (window title)
return

Method 2 would be the same but without hotkeys and 2 separate ahk files (and with ExitApp instead of return)
By method 2 I save all the keys, but somehow I tend to believe method 1 is the more correct way...
A concrete example would be :
Big script with 12 scripts (each with unique hotkey) vs 12 single scripts without any hotkey.

What do you think?
And how do you work?

Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 15:17

I don't entirely understand your question, but you can create separate files and include them into a main one. If you need hotkeys working under certain condition, such as for certain program currently active, you can use #if WinActive() or so.

I always start scripts with a hotkey to reload it, so I can test changes faster.
Use [code=autohotkey] forum tag to share your code.
Click on (Accept this answer) on top-right part of the post if it has answered your question / solved your problem.
User avatar
Scr1pter
Posts: 432
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 17:12

Well, I wonder if starting a new process is worse than executing the script by a hotkey.
When starting a new process, the compiler always has to do some work.

But if your script is already running (e.g. as exe or ahk) and you start it with a hotkey,
it might be "less work" for the PC.
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 17:33

I don't get the question either. I can guess you are asking if a solution to a problem is appropriate...

I am guessing you found the need to isolate the key labels from the code maybe? because the more you add the harder it is to manage? and the more ahk files you make the more you find yourself copy pasting the same code?

AHK supports includes. you can make functions in those includes and you main file would include the files that include the code you want to run and the labels you want to react to...

;My File For This app
;init
#NoEnv
#InstallKeybdHook
#InstallMouseHook
#UseHook On
;#SingleInstance IGNORE
#SingleInstance, off
#Warn ALL
#Persistent
SendMode Input

;includes
#Include Includes\Helpers\HelpfulCode.ahk
#Include Includes\Helpers\HelpfulCode2.ahk

;my keys for this file
^+F2::
WinTitleToClipboard()
Return
...
FanaticGuru
Posts: 1193
Joined: 30 Sep 2013, 22:25

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 17:53

Scr1pter wrote:Well, I wonder if starting a new process is worse than executing the script by a hotkey.
When starting a new process, the compiler always has to do some work.

But if your script is already running (e.g. as exe or ahk) and you start it with a hotkey,
it might be "less work" for the PC.
It is slightly more processor work and memory but multiple processes will create multiple threads the scripts could run concurrently with a slight increase in performance.

In a modern computer all of this is pretty insignification. I would do what ever is best for the human as it makes very little difference to the computer.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
User avatar
Scr1pter
Posts: 432
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 18:02

Yes,
I found out that (for me) in some cases it's easier to create 18 single ahk scripts and to link the ahk files to my programable G keys.
There is no "which key to assign?" - issue and I believe I was able to realize my aim faster.

I'm not really sure if #include will work for me.

Imagine this would be method 1:

Code: Select all

1::
Send Test1
return

2::
Send Test2
return

3::
Send Test3
return
After compiling the script, it runs and whenever I press 1, 2 or 3, the Send gets made.

If I create single scripts like:

Code: Select all

Send Test1
ExitApp

Code: Select all

Send Test2
ExitApp

Code: Select all

Send Test3
ExitApp
I cannot include them in another ahk script, because how would I be able to start them without any keys?
For this reason I assign these ahk files (Test1.ahk, Test2.ahk, Test3.ahk) to my programable G keys of my keyboard.

Instead of
G1 = key 1
G2 = key 2
G3 = key 3

it would be:
G1 = link to C:\...\Test1.ahk
G2 = link to C:\...\Test2.ahk
G3 = link to C:\...\Test3.ahk

And each I time I press the G key, a process gets started and the script gets executed - without assigning any keys.

Edit
By the way, my computer specs:
CPU: Intel Core i5-4590
MB: Asus B85M-G (C2),
GPU: GeForce GTX 1060 6 GB,
RAM: 2x 8 GB DDR3-1600,
SSD: Samsung Evo 850 Basic 500 GB
OS: Win 7 Pro 64 Bit

Regards
I'm not an expert, just an enthusiastic AutoHotkey user. 8-)
Please do not support cheaters!
Keyboard: Logitech G15 first generation - Mice: Logitech G9, G502, G602 - OS: Windows 7 Pro 64 Bit - AHK version: 1.1.29.00
FanaticGuru
Posts: 1193
Joined: 30 Sep 2013, 22:25

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 18:20

Scr1pter wrote:Yes,
I found out that (for me) in some cases it's easier to create 18 single ahk scripts and to link the ahk files to my programable G keys.
There is no "which key to assign?" - issue and I believe I was able to realize my aim faster.

I'm not really sure if #include will work for me.

Imagine this would be method 1:

Code: Select all

1::
Send Test1
return

2::
Send Test2
return

3::
Send Test3
return
After compiling the script, it runs and whenever I press 1, 2 or 3, the Send gets made.

If I create single scripts like:

Code: Select all

Send Test1
ExitApp

Code: Select all

Send Test2
ExitApp

Code: Select all

Send Test3
ExitApp
I cannot include them in another ahk script, because how would I be able to start them without any keys?
For this reason I assign these ahk files (Test1.ahk, Test2.ahk, Test3.ahk) to my programable G keys of my keyboard.

Instead of
G1 = key 1
G2 = key 2
G3 = key 3

it would be:
G1 = link to C:\...\Test1.ahk
G2 = link to C:\...\Test2.ahk
G3 = link to C:\...\Test3.ahk

And each I time I press the G key, a process gets started and the script gets executed - without assigning any keys.

Edit
By the way, my computer specs:
CPU: Intel Core i5-4590
MB: Asus B85M-G (C2),
GPU: GeForce GTX 1060 6 GB,
RAM: 2x 8 GB DDR3-1600,
SSD: Samsung Evo 850 Basic 500 GB
OS: Win 7 Pro 64 Bit

Regards
I would be hesitate to do something like this G1 = link to C:\...\Test1.ahk.

It is one thing to have 10 processes running instead of 1 process. But that is not what is happening here. You are starting and ending a single process over and over. You will pretty much never have more than one process running at a time.
The problem with this is the accessing of the storage device over and over. This is not good even for a SSD. It is also relatively slow.

I would suggest sticking with hotkeys. You can run all the hotkeys together in one script even if using #include to breakup into separate files. Or you can run each hotkey as a separate script.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: How do YOU start most of your AHK scripts?

14 Jun 2018, 18:33

I totally zoned out on the G-key stuff on my first read... sorry.

I personally dont use the gkey system as logitech gaming software has lost my settings too many times on updates...

If you have a ssd drive and you are not that concerned about the time it takes to load the script, compile it and running it, then it is a perfectly reasonable setup.

You can also set the persistent to false at the top of the ahk file which would not require you to call exitapp...

You can also pass parameters to the .ahk or the compiled version thereof, to put all the scripts pertaining to the program you want to tweak

Notepad:
G1 = link to C:\...\Notepad.ahk Func1
G2 = link to C:\...\Notepad.ahk Func2
G3 = link to C:\...\Notepad.ahk Func3

https://autohotkey.com/docs/Variables.htm#BuiltIn
see 1,2,3, etc in the Script Properties table (first entry)

That could improve performance by taking advantage of your drive's caching system if you are prone to launch the file often...

so like if %1% is "Func1" you can call Func1() which you would define in the file...

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Helgef, JoeWinograd, loek3000, Rafio, VarunAgw and 60 guests