Prevent repeat triggering while using KeyWait command Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Lem2001
Posts: 46
Joined: 27 Jun 2017, 17:59

Prevent repeat triggering while using KeyWait command

17 Oct 2019, 17:42

I'm using the following command to trigger an action on a long key press of F12.

Code: Select all

F12::				
KeyWait, F12, T0.6																				
if A_TimeSinceThisHotkey >= 500 ; in milliseconds
However, I want the F12 key to fire off only once per key press (even if it's held down) instead of it repeatedly triggering while the key is being held down.

How can I achieve this while at the same time still having it only work after a long-press?
Hellbent
Posts: 791
Joined: 23 Sep 2017, 13:34

Re: Prevent repeat triggering while using KeyWait command

17 Oct 2019, 17:48

I think that this should do it.

Code: Select all

index:=0

F12 Up::
	Tooltip,% ++Index
	return
***Edit***

NVM, didn't see that you want it for after a long key press.
Hellbent
Posts: 791
Joined: 23 Sep 2017, 13:34

Re: Prevent repeat triggering while using KeyWait command

17 Oct 2019, 18:01

This should do the trick.

Code: Select all

Index:=0

F12::
	StartPress:=A_TickCount
	keywait,F12
	if((A_TickCount-StartPress)>500){
		ToolTip,% ++Index
	}
	return
Lem2001
Posts: 46
Joined: 27 Jun 2017, 17:59

Re: Prevent repeat triggering while using KeyWait command

17 Oct 2019, 18:38

Thank you very much for your reply.

It's almost what I require, but not quite. I would like the action to trigger on key down, not on key up.

At the moment nothing happens while they key is held down. It's only when key is released is the action is triggered.
Hellbent
Posts: 791
Joined: 23 Sep 2017, 13:34

Re: Prevent repeat triggering while using KeyWait command

17 Oct 2019, 18:47

Code: Select all


Index:=0

F12::
	StartPress:=A_TickCount
	while(GetKeyState("F12","P")){
		if((A_TickCount-StartPress)>=500){
			ToolTip,% ++Index
			break
		}else 	{
			Sleep,10
		}
	}

	keywait,F12
	return


Hellbent
Posts: 791
Joined: 23 Sep 2017, 13:34

Re: Prevent repeat triggering while using KeyWait command  Topic is solved

17 Oct 2019, 19:13

I don't use hotkeys often, but I figured that there must be a simpler way to do it than the way I posted above.

Here is what I have. don't think it's going to get any simpler than this.

Code: Select all

Index:=0
F12::
	KeyWait,F12,T0.6	
	if(A_TimeSinceThisHotkey>=500){
		ToolTip,% ++Index
	}
	KeyWait, F12
	return
Lem2001
Posts: 46
Joined: 27 Jun 2017, 17:59

Re: Prevent repeat triggering while using KeyWait command

17 Oct 2019, 20:33

Thank you Hellbent.

Your last code sample works absolutely perfectly!
It behaves exactly as I wanted.

Return to “Ask For Help”

Who is online

Users browsing this forum: MIRKOSOFT, Tom Harding and 238 guests