Press "e" once, some activity, twice another

Get help with using AutoHotkey and its commands and hotkeys
Lumens
Posts: 4
Joined: 02 Feb 2017, 07:35

Press "e" once, some activity, twice another

Post by Lumens » 02 Feb 2017, 07:44

Hi everyone

I need

e:: ; once - any activity /FOR EXAMPLE
Run calc

e and e again :: ; another
Run notepad

Is it possible? Maybe, waiting some milliseconds in the first one, and others in the second one.
enter8
Posts: 96
Joined: 05 May 2016, 16:48

Re: Press "e" once, some activity, twice another

Post by enter8 » 02 Feb 2017, 11:01

This opens calc with a single press of 'e', and it opens calc and notepad if 'e' is pressed twice within 300 milliseconds. Not quite what you asked for, but should be enough to get you started.

Code: Select all

e::
	Presses += 1
	SetTimer, ResetPresses, -300 ; 300 millisecond wait
	GoSub, Presses%Presses%
	return

	ResetPresses:
	Presses := 0
	return

	Presses1:
	run calc
	TrayTip, %A_ThisLabel%, press e once to run calc
	return

	Presses2:
	run notepad
	TrayTip, %A_ThisLabel%, press e twice to run notepad
	return
Lumens
Posts: 4
Joined: 02 Feb 2017, 07:35

Re: Press "e" once, some activity, twice another

Post by Lumens » 02 Feb 2017, 11:46

Thank you! It works.
But unfortunately, when I press twice, It produces both actions.
Do you have any idea how can I improve it?
guest3456
Posts: 2418
Joined: 09 Oct 2013, 10:31

Re: Press "e" once, some activity, twice another

Post by guest3456 » 02 Feb 2017, 13:18

you could probably use the A_TimeSincePriorHotkey built in variable

but this was easy enough:

Code: Select all

e::
   Input, NextKey, L1 T0.5
   if (NextKey = "e")
      Run, notepad
   else
      Run, calc
return


User avatar
jeeswg
Posts: 5113
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Press "e" once, some activity, twice another

Post by jeeswg » 02 Feb 2017, 15:39

I've been curious to write a double-tap hotkey, because I haven't done one before.
This method is flexible for any hotkey.
I like the Input approach because it is more elegant, however,
it might be fiddly to get it to work with certain hotkeys.

Code: Select all

^x::
if vInProgress
{
SetTimer, Presses1, Off
Run, notepad ;2 key presses
vInProgress := 0
Return
}
SetTimer, Presses1, -300
vInProgress := 1
Return

Presses1:
Run, calc ;1 key press
vInProgress := 0
Return
Lumens
Posts: 4
Joined: 02 Feb 2017, 07:35

Re: Press "e" once, some activity, twice another

Post by Lumens » 02 Feb 2017, 15:49

Thank you everyone!

As ever, AHK has many options to resolve our wishes
Post Reply

Return to “Ask For Help”