Just need a script that sends the "Esc" key when I double tap the Spacebar

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sk0r
Posts: 2
Joined: 27 Oct 2021, 07:07

Just need a script that sends the "Esc" key when I double tap the Spacebar

27 Oct 2021, 07:11

My Google results when trying to search for other forum posts about this only come up with people asking for the opposite: pressing one key to send a double tap of another. So if anyone can help me with a simple script to send the Escape key when I double tap the Space bar that'd be excellent. Thank you!
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Just need a script that sends the "Esc" key when I double tap the Spacebar

27 Oct 2021, 08:13

example with 'morse' ( user @flyingDman )
https://www.autohotkey.com/board/topic/146902-typing-using-the-numpad-like-on-old-phones/
EDIT : small modified for test > send $ if use space twice, otherwise send space

Code: Select all

;- https://www.autohotkey.com/board/topic/146902-typing-using-the-numpad-like-on-old-phones/
#warn
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
$space::
p := Morse()
If (p = "1")
    {
	;msgbox, 262208,LONG-PRESS ,0-LONG PRESS,1  ;- longer press as timeout
    send,{space}
    }
If (p = "0")
    {
    ;msgbox, 262208, ,1-times,1
    send,{space}
    }
If (p = "00")
    {
    ;msgbox, 262208,SEND $ ,2-times,1
    Send,{text}$
    ;Send,{ESC}
    }
If (p = "000")
    {
    ;msgbox, 262208, ,3-times,1
    send,{space 3}
    }
return
;------------
esc::exitapp
;------------
Morse(timeout = 200) { ;
   tout := timeout/1000
   key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
   pattern:=""
   Loop {
      t := A_TickCount
      KeyWait %key%
      Pattern .= A_TickCount-t > timeout
      KeyWait %key%,DT%tout%
      If (ErrorLevel)
         Return Pattern
   }
}
;============================================================
Last edited by garry on 27 Oct 2021, 08:47, edited 1 time in total.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Just need a script that sends the "Esc" key when I double tap the Spacebar

27 Oct 2021, 08:30

Code: Select all

$Space::
    KeyWait, Space, T0.2
    If !(ErrorLevel)
    { 
        Sleep, 300
        If (A_PriorHotKey = "$Space Up") ; double tap
            Send {Esc}
        else                             ; single tap 
            Send {Space}
    }
    else                                 ; press-and-hold
	{
		while GetKeyState("Space", "P")
			Send {Space}                ; sends Space continuously 
	}
return
                                                                                                                
$Space Up:: return
Last edited by GEV on 27 Oct 2021, 11:43, edited 1 time in total.
sk0r
Posts: 2
Joined: 27 Oct 2021, 07:07

Re: Just need a script that sends the "Esc" key when I double tap the Spacebar

27 Oct 2021, 08:44

Perfect! Thank you both SO much, now that I've seen how it works I can start to experiment a little further. That's how I've been learning AHK (very slowly lol), just dissecting existing scripts and making them custom to my own needs. This was just the one time I couldn't find a similar script to Franken-script the pieces together lol.

Cheers!
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: Just need a script that sends the "Esc" key when I double tap the Spacebar

27 Oct 2021, 08:51

@GEV , works fine, I've forget : > else send space ( if tap space once ) or if tap 3-times > then send 3 spaces

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: FanaticGuru, filipemb, LRRUNB and 203 guests