TapHold script ("Autoshift" alphabetic letters)?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ThomCD
Posts: 2
Joined: 08 Apr 2021, 08:01

TapHold script ("Autoshift" alphabetic letters)?

09 Apr 2021, 10:46

Tap a key or hold that key and it prints the SHIFTED Key. I was scanning the scattered scripts in Autohotkey Forum
ex. https://www.autohotkey.com/boards/viewtopic.php?t=37216 and a couple of others or User evilC posted great stuff with a sophisticated and dedicated https://github.com/evilC/TapHoldManager
However I am confused how to get a robust solution, which is also somehow simpler then e.g. evilC superrich code? What way to go?
Could I just "loop" to get the key hit and send it with a SHIFT, means not to write out every and each single key?

Sorry, I am newbe noobs to AHK with this.

How about this? Altered snippet from https://autohotkey.com/board/topic/81642-help-with-script-tap-keyhold-key-sending-different-command/

Code: Select all

Send = 

z::
KeyWait, z, T0.150
If ErrorLevel = 1
	Send = {Z Down}{Z Up}
else
	Send = {z down}{z up}
return

z Up::
Send %Send%
Return
It looks so much simpler and accessible to me then some of multi_tap/hold scripts. I don't need multi-tapping. Just TAP/HOLD, 150ms wait

Problem: I have to wait out the 150ms, or otherwise interferes with a quickly typed following letter. I guess I need an "End" function in the moment a next key is pressed or something like that. Hm...?

Anyone out there who has already tinkered with this (alphbetical and numbers to "AUTOSHIFT" when HOLD over ca 200 ms) and found a good solution?

Appreciate greatly some help on this...
Last edited by gregster on 09 Apr 2021, 19:07, edited 1 time in total.
Reason: Topic moved to 'Ask For Help' (v1).
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: TapHold script ("Autoshift" alphabetic letters)?

09 Apr 2021, 11:45

It doesn't wait the whole 0.150 seconds. It moves on as soon as it's released. That's what KeyWait does. It only times out after 0.150 seconds if continually held for that long which is then used to determine it was was held down for at least that long. However, I think 0.150 is too short to work with physically. I suggest 0.3 seconds, and simplifying the script to the following makes it work much more smoothly in my testing:

Code: Select all

$z:: ; the $ prevents the script from triggering its own hotkey
KeyWait, z, T0.3
If (ErrorLevel = 1)
	Send Z
else
	Send z
return

By the way, you posted in the v2 forum, which is not the latest official release of AutoHotkey. It is in the alpha testing phase. You are using v1 as evidenced by your code, so you should post in the regular part of "Ask For Help" going forward.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: TapHold script ("Autoshift" alphabetic letters)?

09 Apr 2021, 11:53

This version is probably better, so it doesn't send another z after holding for a Z for too long (plus a shorthand version of the conditional statements):

Code: Select all

$z::
KeyWait, z, T0.3
Send, % ErrorLevel = 1 ? "Z" : "z"
KeyWait, z
return

It' s always going to cause an issue for a fast touch typist, however, just because it has to execute code between every keypress of the affected hotkeys. The following sets up the above for all 26 letters, and you have to type pretty slowly for it not to make mistakes:

Code: Select all

loop, 26
	Hotkey, % "$" Chr(Ord("a") + A_Index - 1), SendCap
return

SendCap:
	ThisKey := SubStr(A_ThisHotkey, 0)
	KeyWait, % ThisKey, T0.3
	Send, % ErrorLevel = 1 ? Chr(Ord(ThisKey) - 32) : ThisKey
	KeyWait, % ThisKey
return
ThomCD
Posts: 2
Joined: 08 Apr 2021, 08:01

Re: TapHold script ("Autoshift" alphabetic letters)?

10 Apr 2021, 06:09

@boiler thank' so much for the suggestions. And sorry for tapping in the wrong forum.

I am kind of more confident with the first version. (Which needs however defining all letters.. :roll: ) -- but this has an advantage: e.g.: letters E and R are neighboured keys, so I press them fairly quickly. Hence in the first version I can set up individual waittimes. Infact I am experimenting with 100 ms... 140 ms . In general I am well off with 170 ms waittime, not above 200 ms, as it really slows down my movement to much.

You are definitely right in that one has to control the typing speed (i.e. hammering down like on an old mechanical typewriter...) but this might be the price tag for some gain in ergonomics. What I am looking for, and not speed gain.

Thank you so much for your suggestions to a simple solution for a somehow not so trivial question (for me)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, arcylix, drani, Rohwedder and 201 guests