How to assign both (single and double press) to the same key Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Moaz93
Posts: 16
Joined: 05 Aug 2018, 12:32

How to assign both (single and double press) to the same key

Post by Moaz93 » 19 Sep 2021, 04:47

Hi every one,
I'm having a trouble figuring out this code, I'm trying to press F1 single time for toggling Wi-Fi on, and a double press for toggling it off.
but with no luck, it said (error, double hotkey!)

Code: Select all

F1::run,C:\Windows\System32\cmd.exe /c (netsh interface set interface Wi-Fi enabled)
~F1::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey <= 300)
	send {Launch_App1}
return
Launch_App1::run,C:\Windows\System32\cmd.exe /c (netsh interface set interface Wi-Fi disable)
If I remove the first line, it works only for double press.
any ideas?
thanks
Rohwedder
Posts: 7512
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to assign both (single and double press) to the same key

Post by Rohwedder » 19 Sep 2021, 05:17

Hallo,
try (untested):

Code: Select all

F1::
IF TF1 := !TF1
	SetTimer, TF1, -500
Return
TF1:
IF TF1
{
	run,C:\Windows\System32\cmd.exe /c (netsh interface set interface Wi-Fi enabled)
	TF1 =
	Return
}
Launch_App1::run,C:\Windows\System32\cmd.exe /c (netsh interface set interface Wi-Fi disable)
Moaz93
Posts: 16
Joined: 05 Aug 2018, 12:32

Re: How to assign both (single and double press) to the same key

Post by Moaz93 » 19 Sep 2021, 06:28

Rohwedder wrote:
19 Sep 2021, 05:17
try (untested)
WOW thanks! it worked!!

just some questions,

1- is it possible to have multiple presses? like 3 or 4?
2- if I want to assign (the actual key itself) if pressed once, for example if I assined the (P) key, would it still behave the same? as a normal typing key?
3- can I remove the extra button (launchApp1)? and keep the run command only? I tried and it worked, but it keeps launching explorer window!? is there a fix?
Rohwedder
Posts: 7512
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to assign both (single and double press) to the same key  Topic is solved

Post by Rohwedder » 19 Sep 2021, 07:45

1- is it possible to have multiple presses? like 3 or 4?

Code: Select all

F1::SetTimer, TF1, -400,% TF1++:= "0" TF1
TF1:
Switch, TF1
{
Case 1: ToolTip, only once
Case 2,3: ToolTip, 2 or 3 times
Default: ToolTip,% TF1 " times? Parkinson diagnosis!"
}
SoundBeep, 1000*TF1, 1000, Tf1:=0
ToolTip
Return
2- if I want to assign (the actual key itself) if pressed once, for example if I assined the (P) key, would it still behave the same? as a normal typing key?

Code: Select all

~*p::SetTimer, Tp, -400,% Tp:=1
#If Tp
*p::SetTimer, Tp, -400,% Tp++
#If
Tp:
Switch, Tp
{
Case 1:
Case 2,3:
ToolTip, 2 or 3 times
SoundBeep, 2000, 1000
Tooltip
}
Tp = 0
Return
3- ??:

Code: Select all

F1::run,%ComSpec% /c (netsh interface set interface Wi-Fi enabled),, hide
Moaz93
Posts: 16
Joined: 05 Aug 2018, 12:32

Re: How to assign both (single and double press) to the same key

Post by Moaz93 » 20 Sep 2021, 09:23

Thank you so much for the help, Although, it took a while to figure out how to remove the unnecessary "jokes" :roll:
any way, thanks a lot!
Post Reply

Return to “Ask for Help (v1)”