How to create a Local Static Variable in a Hotkey or something similar

Get help with using AutoHotkey and its commands and hotkeys
jwinfl
Posts: 41
Joined: 16 Aug 2017, 12:37

How to create a Local Static Variable in a Hotkey or something similar

28 Feb 2020, 09:24

I need a local static variable in several hotkeys.

Or something similar, so when the hotkey fires it can check to see if it should send delete or ignore it.

In the following example, if ^!x is pressed more than once in 2 seconds it would not send delete again until 2 seconds elapsed.

The following code results in an error... "static inuse := false" does not contain a recognized action (apparently static can not be used in a hotkey like it can in a function).

^!x::
static inuse := false
if inuse
return
inuse := true
sendinput {del}
sleep 2000
inuse := false
return
User avatar
boiler
Posts: 6148
Joined: 21 Dec 2014, 02:44

Re: How to create a Local Static Variable in a Hotkey or something similar

28 Feb 2020, 11:03

This is a good use for the built-in variable A_TimeSinceThisHotkey:

Code: Select all

^!x::
if (A_TimeSinceThisHotkey > 2000)
	SendInput {Del}
return

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], Lem2001, Visioneer, wineguy and 41 guests