Question about how autohotkey works

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Question about how autohotkey works

Post by tatagi » 01 Oct 2022, 06:34

Hello! I want to know how AHK's hotkey works.

#IfWinActive ahk_class Chrome_WidgetWin_1
^t::send !a
#IfWinActive


the hotkey above works only when there's active chrome window, otherwise it is ignored.

Question is, what exactly happens when I press ctrl + t combination somewhere else, not on chrome?
does it still try to check if I am on chrome and if yes perform the send command, or does it simply do nothing on AHK end?, I mean, nothing, not even a checkup?

probably it can be between this two:
1. When hotkey is pressed, the AHK program detects it is pressed on whatever windows that is active, and then it check if that window is the that of predefined program, and then if so, it sends what it is asked to send, for the above, Alt + a
2. Or, the AHK program execute the script only when Chrome window is open and active, so if active window is not Chrome's(e.g. notepad), then AHK script is not called up and ^t does what it is supposed to do in that program.

I ask this because there's list of hotkeys that are plain single characters like A or 5 and used as hotkey only in specific programs, in this case if the answer is 1, it will possibly and unnecessarily uses the CPU no matter how heavy it will be. imagine how many times a or 5 will be used in writing some novels or anything.

thank you.

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

Re: Question about how autohotkey works

Post by mikeyww » 01 Oct 2022, 06:45

Could always do some reading about this. https://www.autohotkey.com/docs/commands/_IfWinActive.htm#gen
For performance reasons, #IfWin does not continuously monitor the activation or existence of the specified windows. Instead, it checks for a matching window only when you type a hotkey or hotstring. If a matching window is not present, your keystroke or mouse click is allowed to pass through to the active window unaltered.
I would challenge you to prove that the added CPU usage is anything greater than approximately zero.

Rohwedder
Posts: 7627
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Question about how autohotkey works

Post by Rohwedder » 01 Oct 2022, 08:13

Hallo,
try this audible script flow:

Code: Select all

q::SoundBeep, 1000, 20
w::SoundBeep, 2000, 20
#If WinActive("ahk_class Chrome_WidgetWin_1"), SoundBeep()
w::SoundBeep, 2000, 20
e::SoundBeep, 3000, 20
#If !WinActive(), SoundBeep()
e::SoundBeep, 3000, 20
SoundBeep()
{
	SoundBeep, 4000, 20
}

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Question about how autohotkey works

Post by lexikos » 01 Oct 2022, 17:58

You're free to close the script when you don't need it, but computers are meant to save you time, not vice versa. If it takes you a few seconds to start or stop the script, that's probably about a million times as long as the program takes to check the active window when you press a hotkey. If it takes you a fraction of a second to press and release a key, the CPU is probably still being used less than 1% of that time to process it.
... it will possibly and unnecessarily uses the CPU no matter how heavy it will be.
Heavy? I have no idea what you mean.

Using the CPU is necessary to make the computer do anything useful. Every time you press a key, the operating system is using the CPU to process your input. There is a lot of work going on behind the scenes that you never notice, because it doesn't happen on a human timescale.

Post Reply

Return to “Ask for Help (v1)”