A 'Tap and Hold' script

Post your working scripts, libraries and tools for AHK v1.1 and older
gibenedek
Posts: 53
Joined: 20 Sep 2020, 19:51

A 'Tap and Hold' script

24 Oct 2020, 01:16

I dunno. I made it, it took some time, but it looks amazing. And since I can share it in like 5 buttons, here yalls go. It needs CONSOLAS font, which is helpful for me anyway, its a monospaced one that looks normal. Easy for making tables and pretty formatting, and useful enough to use as a standard font for my pc. If it looks Wonkey, just paste it into a text editor and pop on consolas.

While its here, I cant seem to get it so I can use less specific hotkeys, and use more variables...to make it more...well...variable. Haha. If anyone has a go at it, thatd be appreciated.

Lastly, I made some simple and complex hotstings for coding. Separators and shortcuts and such (THAT WHOLE THING DOWN THERE IS A HOTSTRING) so if ya want, reply ill send the script.

Enjoy your day.

Code: Select all


;‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\ .════════════════════════════════════════╗
Timer: ; 								; -  - triple Tap + Hold - BLOCK 1 -  -   ║
   { ;      							; This is the block that starts           ║
	If !%A_ThisHotkey%key               ; the count forall Hotkeys.               ║               	
	SetTimer, %A_ThisHotkey%key, -400   ; Make sure it is placed above            ║
	%A_ThisHotkey%key++                 ; Block 2 & that the prefix is changed    ║
	Return                              ; to match the key's Name, as only 1      ║                       
			} 							; may Exist. instance of this lable       ║
;______________________________________/ `════════════════════════════════════════╝

q:: gosub timer    
;‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\      
qkey:				                         ;           ╔══════════════════╗
If GetKeyState("q","P") and %A_ThisLabel%=1  ;>----------║   Hold  Action   ║              
		msgbox 4		                     ;           ╚══════════════════╝
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +
   Else If %A_ThisLabel% = 3                 ;           ╔══════════════════╗
      	    msgbox 3			             ;>----------║ 3X Press  Action ║
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +           ╚══════════════════╝
   Else If %A_ThisLabel% = 2                 ;           ╔══════════════════╗
	    msgbox 2			                 ;>----------║ 2X Press  Action ║
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +           ╚══════════════════╝		
   Else If %A_ThisLabel% = 1                 ;           ╔══════════════════╗
	    msgbox 1			                 ;>----------║ 1X Press  Action ║
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +	         ╚══════════════════╝
%A_ThisLabel%=0                              ;
 return                                      ;
;___________________________________________/
[Mod edit: Font-tags removed from code box.]
[Mod edit: Provisional topic name added.]
gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: A Donaton to the community.

24 Oct 2020, 02:38

@gibenedek: Please add a meaningful description to the topic title -and ideally to the post itself, about what this is supposed to do and how to use it.
Thank you!
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: A Donaton to the community.

24 Oct 2020, 06:58

Thank you for this "Tap or Hold" snippet.
but the script you posted doesn't work. :cry:
I fixed it here. ;)
I guess there are other ways to do that. :think:

Code: Select all

; triple Tap or Hold key snippet


;??????????????????????????????????????\ .----------------------------------------+
return                                  ;                                         ¦
Timer:   								; -  - triple Tap + Hold - BLOCK 1 -  -   ¦
   {        							; This is the block that starts           ¦
	If !%A_ThisHotkey%key               ; the count forall Hotkeys.               ¦
	SetTimer, %A_ThisHotkey%key, -400   ; Make sure it is placed above            ¦
	%A_ThisHotkey%key++                 ; Block 2 & that the prefix is changed    ¦
	Return                              ; to match the key's Name, as only 1      ¦
			} 							; may Exist. instance of this lable       ¦
;______________________________________/ `----------------------------------------+



Q:: goto timer    
;???????????????????????????????????????????\      
qkey:				                         ;           +------------------+
If GetKeyState("q","P") and %A_ThisLabel%=1  ;>----------¦   Hold  Action   ¦
     msgbox you held down the key Q          ;           +------------------+
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +
   Else If %A_ThisLabel% = 3                 ;           +------------------+
    msgbox you pressed the key Q 3 times     ;>----------¦ 3X Press  Action ¦
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +           +------------------+
   Else If %A_ThisLabel% = 2                 ;           +------------------+
	msgbox you pressed the key Q 2 times     ;>----------¦ 2X Press  Action ¦
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +           +------------------+
   Else If %A_ThisLabel% = 1                 ;           +------------------+
	 msgbox you pressed the key Q 1 time	 ;>----------¦ 1X Press  Action ¦
;  -  -  -  -  -  -  -  -  -  -  -  -  -  -  +	         +------------------+
%A_ThisLabel%=0                              ;
 return                                      ;
;___________________________________________/


key:
return
gibenedek
Posts: 53
Joined: 20 Sep 2020, 19:51

Re: A Donaton to the community.

26 Oct 2020, 07:59

Thanks, and sorry. Im new, and the focus was on the formatting. I hate ugly looking code...its harder to manage once my scripts get longer. Anyway youre right, I should have posted what it is, and clearly it should not have been bropken.

Actually I didnt know where it came from, I found it in a folder called triple tap hold and it worked. Then didnt, hence the change from %A_variable% to the actual key I was using. Weird part, was that it was working again when I posted, as its currently my F10 action. Anyway, I hope the formatting is enjoyed. I will be more thoughtful with my titles.
Se7en
Posts: 2
Joined: 24 Oct 2020, 08:34

Re: A 'Tap and Hold' script

30 Oct 2020, 07:57

Your code look very beautiful!
And I think it's very useful also.
Thanks.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: sanmaodo and 179 guests