controlling hotstring replacement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

controlling hotstring replacement

Post by colt » 08 Feb 2023, 17:13

I want to use a hotstring to enter the date by holding down the 'd' key or by typing three individual chars. The hostring should only enter the date once and then become idle until I release the key.
I code below nearly works except it keeps deleting chunks of text the longer I hold down the 'd' key. I assume it is because the hotstring code is being triggered even though the character is consumed.
Maybe there is another technique that is better?

Code: Select all

hotkey,d,off
return

d::
return

:*?:ddd::	
	hotkey d,on ;consume extra characters
	sendInput %A_now%
	loop 
	{
		if(!getKeyState("D","P"))
		{			
			hotkey d,off ;allow pass through again		
			break
		}
		sleep 50
	}
return


User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: controlling hotstring replacement

Post by mikeyww » 08 Feb 2023, 19:00

Code: Select all

#Requires AutoHotkey v1.1.33
presses := 0, squelch := 500

$d::
KeyWait d, T.5
If ErrorLevel { ; Held
 SendInput % A_Now
 presses := 0
 KeyWait d
} Else {
 SetTimer Done, % -squelch
 presses++
}
Return

Done:
If (presses < 3)
 Loop % presses
  SendInput d
Else SendInput % A_Now
presses := 0
Return

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: controlling hotstring replacement

Post by gmoises » 08 Feb 2023, 19:02

You can have many HotStrings

Code: Select all

#Requires AutoHotkey v1.1.36+
:::*?::
	sendInput % A_now
Return

::ddd::
	sendInput % A_now
Return

colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: controlling hotstring replacement

Post by colt » 09 Feb 2023, 22:43

Thanks for the suggestions. mikeyww, yours worked great while holding down, but I couldn't get a standard three key press hotstring to trigger along side that code.
I ended up getting the behavior I wanted by resetting the hotstring recognizer inside the loop.

I wonder if there is a way to self contain it without the external label.

Code: Select all

consume:
return

:*?:ddd::	
	hotkey,d,consume,on	
	sendInput %A_now%
	loop 
	{
		Hotstring("Reset") ;keep reseting recognizer until key released
		if(!getKeyState("D","P"))
		{			
			hotkey,d,consume,off ;allow pass through again
			break
		}		
		sleep 50
	}
return

Post Reply

Return to “Ask for Help (v1)”