Perform action only when nothing else was pressed...

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
4k3or3et
Posts: 35
Joined: 23 Jan 2019, 13:58

Perform action only when nothing else was pressed...

19 May 2020, 13:49

Hi Guys

I have simple script:

Code: Select all

appskey::
send {alt down}{space}{alt up}
return
What I need to achieve is to execute {alt down}{space}{alt up} action only when AppsKey was pressed alone. For example if i press AppsKey+a then {alt down}{space}{alt up} should not be executed.

Can anyone help me how to achieve that?

The thing is that i have two script running at the same time. One is elevated, second it not. The problem is that when I press AppsKey+A the elevated script is also executing {alt down}{space}{alt up} which is not desired at that time.

Thanks for any help.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Perform action only when nothing else was pressed...

20 May 2020, 01:59

The easiest way I can think of is to run a timer every 100ms, and check for the key state of that key.

Code: Select all

SetTimer, CheckAppsKey, 100

CheckAppsKey() {
	keyState := GetKeyState("AppsKey","P")
	If (keyState = 1) {
		; do stuff
	}
}
But i would not recommend doing it this way. Does this need to be a global hotkey? Or are you pressing this while a script GUI window is active?
4k3or3et
Posts: 35
Joined: 23 Jan 2019, 13:58

Re: Perform action only when nothing else was pressed...

20 May 2020, 03:49

Thank you for you reply. Yes it has to be global hotkey... :-/
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Perform action only when nothing else was pressed...

20 May 2020, 09:46

I've been racking my brain and I can't think of any other better method for the time being ... try the script i posted ... make sure the SetTimer command is above all of your specified hotkeys. It should work just fine.

I tested it on my machine with the Ctrl button, and it worked.

Here's a more complete simple example:

Code: Select all

SetTimer, CheckAppsKey, 100

CheckAppsKey() {
	keyState := GetKeyState("Ctrl","P")
	If (keyState = 1) {
		msgbox "Ctrl pressed!"
	}
}

F12::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Freddie, gongnl, mmflume, ShatterCoder and 90 guests