Page 1 of 1

Prevent repeat triggering while using KeyWait command

Posted: 17 Oct 2019, 17:42
by Lem2001
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?

Re: Prevent repeat triggering while using KeyWait command

Posted: 17 Oct 2019, 17:48
by Hellbent
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.

Re: Prevent repeat triggering while using KeyWait command

Posted: 17 Oct 2019, 18:01
by Hellbent
This should do the trick.

Code: Select all

Index:=0

F12::
	StartPress:=A_TickCount
	keywait,F12
	if((A_TickCount-StartPress)>500){
		ToolTip,% ++Index
	}
	return

Re: Prevent repeat triggering while using KeyWait command

Posted: 17 Oct 2019, 18:38
by Lem2001
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.

Re: Prevent repeat triggering while using KeyWait command

Posted: 17 Oct 2019, 18:47
by Hellbent

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



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

Posted: 17 Oct 2019, 19:13
by Hellbent
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

Re: Prevent repeat triggering while using KeyWait command

Posted: 17 Oct 2019, 20:33
by Lem2001
Thank you Hellbent.

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