Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

25 May 2018, 09:37

I am using a beautiful script written by John Guidry [iswitchw] to summon my "opened windows". Yet, I would like to remap the hotkey to activate the script.

Question: how to I declare the following sequence of keystrokes as a hotkey?
  • 1. While holding Ctrl key, press the Space bar twice
    2. While holding Ctrl key, press Space bar three times
I find myself mistype `^Space` (Ctrl + Space) a lot, when editing my texts.
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

25 May 2018, 11:08

Hallo,
try:

Code: Select all

^Space::
SetTimer, No, -500
No++
Return
No:
	If No > 1
		MsgBox, % No " ^Spaces"
	No =
Return
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

25 May 2018, 13:53

Rohwedder wrote:Hallo,
try:

Code: Select all

^Space::
SetTimer, No, -500
No++
Return
No:
	If No > 1
		MsgBox, % No " ^Spaces"
	No =
Return
Thanks for your script, after the attached error message when I run the script afresh, I do get a message box displaying how many spaces I've run. Yet, are there a easier syntax that will declare such sequence of key-strokes as a "standalone shortcut"? Ideally, I am looking for a magic syntax of the following form:

Code: Select all

[Something Magic, ^DoubleSpace]::
In particular, I would like to replace the mapping of `#space` on line 79 in the source file: iswitchw.ahk. Based on my limited AHK knowledge, I don't quite understand the control structure in the source file.

Questions in short:
  • 1. How to properly initialize the counter variable `No`?
    2. Are there magical syntax that defines Ctrl+DoubleSpace, that I can put to the left of a `::` sign?
Thanks a lot!
Attachments
AHK_warning.jpg
AHK_warning.jpg (101.67 KiB) Viewed 2496 times
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

25 May 2018, 16:17

Code: Select all

^Space::expectSecondSpace := true

#If expectSecondSpace
^Space::
{
	MsgBox, % "ctrl+space+space"
	expectSecondSpace := false
return
}
#If

~*Ctrl Up::expectSecondSpace := false

Esc::ExitApp
e: return was missing
Last edited by swagfag on 26 May 2018, 04:11, edited 1 time in total.
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

25 May 2018, 23:21

Hallo,
untested!
1. comment out: #Warn in line 60
2. replace

Code: Select all

#space
by

Code: Select all

DSpace:
DSpace =
Hotkey, ~*Ctrl Up, Off
Return
^Space::
DSpace++
Hotkey, ~*Ctrl Up, DSpace
If DSpace < 2
	Return
Gosub, DSpace
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

26 May 2018, 00:40

Rohwedder wrote:Hallo,
untested!
1. comment out: #Warn in line 60
2. replace

Code: Select all

#space
by

Code: Select all

DSpace:
DSpace =
Hotkey, ~*Ctrl Up, Off
Return
^Space::
DSpace++
Hotkey, ~*Ctrl Up, DSpace
If DSpace < 2
	Return
Gosub, DSpace
I think we are close. Yet, the attached error message is generated, pointing out that `~*Ctrl Up` is not a valid hotkey.

I am attaching both the error message and the current version of the script.

Thanks a lot!
Attachments
Foreign_is_win_Switch.ahk
Script that yields the error.
(18.78 KiB) Downloaded 35 times
AHK_Error.jpg
Incorrect hotkey.
AHK_Error.jpg (126.61 KiB) Viewed 2472 times
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

26 May 2018, 00:41

swagfag wrote:

Code: Select all

^Space::expectSecondSpace := true

#If expectSecondSpace
^Space::
{
	MsgBox, % "ctrl+space+space"
	expectSecondSpace := false
}
#If

~*Ctrl Up::expectSecondSpace := false

Esc::ExitApp
Thank you for your suggestion!
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Hotkey declaration: how to map a sequence of keystrokes as the Hotkey?

26 May 2018, 00:42

swagfag wrote:

Code: Select all

^Space::expectSecondSpace := true

#If expectSecondSpace
^Space::
{
	MsgBox, % "ctrl+space+space"
	expectSecondSpace := false
}
#If

~*Ctrl Up::expectSecondSpace := false

Esc::ExitApp
Thank you for your suggestion! :superhappy:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Oblomov228, uchihito and 170 guests