Double Pressing Script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
plciula
Posts: 4
Joined: 11 Dec 2017, 23:26

Double Pressing Script

11 Dec 2017, 23:33

Hello All,

I'm pretty new to AHK, so forgive me if I'm being silly. I have a media key that I would like to utilize for two different functions. I compiled this based off what I could find in documentation.

Code: Select all

Volume_Mute::

	if (A_PriorHotkey <> "Volume_Mute" or A_TimeSincePriorHotkey > 400)
	{
	KeyWait, Volume_Mute
	Send Single Press
	return
	}
	Send Double Press 
	
Return
Unfortunately, when I double click the key, it outputs "Single PressDouble Press"

Any ideas why this might be happening?
xatmo

Re: Double Pressing Script

12 Dec 2017, 06:43

the way you have it now the send outside the if will still get executed even if the if statement is true or not. u should prob put the outside send with an else
plciula
Posts: 4
Joined: 11 Dec 2017, 23:26

Re: Double Pressing Script

12 Dec 2017, 08:43

Not quite. When I press the key only once, it only sends "Single Press".
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Double Pressing Script

12 Dec 2017, 09:28

Anything inside the IF, will be executed if you press the key once, anything outside the IF will be executed after you press it twice.
There no... easy way to go around this, but I do have one way to do it.

Code: Select all

Volume_Mute::
	If (A_PriorHotkey <> "Volume_Mute" or A_TimeSincePriorHotkey > 400) {
		KeyWait, Volume_Mute
		SinglePress := True
	}
	If (SinglePress)
		SendInput, Single Press
	Else
		SendInput, Double Press
	SinglePress := False
Return

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

plciula
Posts: 4
Joined: 11 Dec 2017, 23:26

Re: Double Pressing Script

12 Dec 2017, 13:10

Unfortunately, that doesn't seem to work either. It still sends "Single PressDouble Press" with every double press. Otherwise both your revision and my original code works just fine. The only thing that isn't working, is the need to suppress the output "Single Press" when the key is double pressed.
User avatar
Bon
Posts: 17
Joined: 11 Jan 2014, 07:31

Re: Double Pressing Script

13 Dec 2017, 10:58

Quidquid Latine dictum sit altum videtur
"Anything said in Latin sounds profound"
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Double Pressing Script  Topic is solved

20 Dec 2017, 17:27

I had a go at a double press hotkey script:

Code: Select all

q:: ;double press hotkey
if (A_PriorHotkey = "q" && A_TimeSincePriorHotkey < 300)
{
	SetTimer, SinglePress, Off
	SendInput, Double Press
	return
}
SetTimer, SinglePress, -300
return

SinglePress:
SendInput, Single Press
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Double Pressing Script

21 Dec 2017, 02:32

@ plciula
any reason why you've posted your thread in a section like this:
Scripts and Functions
Post your working scripts, libraries and tools


... instead of "Ask for Help" (where we moved it to - on your behalf) ??

:thumbdown:
plciula
Posts: 4
Joined: 11 Dec 2017, 23:26

Re: Double Pressing Script

22 Dec 2017, 12:56

Sorry all, been a little busy to mess around with the script.

@Bon
I'm sure that my answer is hidden in the page you linked, just haven't had time to look into it.

@jeeswg
Your solution works perfectly. I have marked it as the answer.

@BoBo
It's because I'm new to the forum, and didn't know that section existed.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot] and 165 guests