long press

Post your working scripts, libraries and tools
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

long press

28 Jan 2017, 18:53

Image

long press a key to send an alternate key, symbol or string

if youve ever found yourself with a mug of tea/coffee in one hand while contorting the other just to send some shift characters like ? or + then this is the script for you

or if youve ever done a google search for "bullet point" just to get the • symbol then this will be a great time saver :D

long press (github)
long press (download.zip)

Code: Select all

[ini example]
/           = {?}                   ; send an alternate key (comments are allowed here)
b           = {U+2022}              ; send unicode
e           = [email protected]        ; send a string
Backspace   = delete_previous_word  ; run a label
if there is a label that matches the ini value then that will be run, otherwise the send command is used, so you know the drill... keys, strings or a combination of both can be used.

here is the key list i use https://gist.github.com/davebrny/ec0b10 ... d6183e52ab
its mostly set up to send the corresponding shift symbol of each key, then i filled up the rest with unicode characters that i will probably never use

check out the github page for more info
User avatar
boiler
Posts: 2607
Joined: 21 Dec 2014, 02:44

Re: long press

28 Jan 2017, 19:37

This is a great idea. I think that if nothing else, I will use it to map the control-key combinations to long presses of those keys. I don't like having to move my hands off the home row for ^c, ^v, ^f, etc. Basically, I may never have to look down at the keyboard again. Thanks for sharing.

You've submitted some really nice tools. I'm already using the in-line calculator. Keep up the good work!
User avatar
boiler
Posts: 2607
Joined: 21 Dec 2014, 02:44

Re: long press

29 Jan 2017, 15:39

Well, I spoke too soon. I have to say the idea is nice, but after trying it, it doesn't work for how I planned to use it. If I try to use a long-press c in place of ^c, it actually replaces the text I have highlighted with a c, then backspaces over it when it realizes that you want to long press instead. So it deletes my text that I wanted to copy.

For this to work properly, rather than sending the character first then backspacing, it should "eat" the keystroke and determine if it is a long press or not. If it is, then do the long press, then if it's not, it can send the normal key through. It should work that way even for a normal keypress like replacing 1 with ! when you long press 1. I don't want to see it type a 1 before replacing it with a !. It should wait until I release the key then type a 1 or ! depending on how long I held the key.

Also, the spam number doesn't seem to work right. If I change it to a very long number to represent several seconds (basically saying I never want it to spam so I don't have to be too precise on my long press duration), it didn't work. It would start spamming the regular key way before then.

If you can address those issues, I would find it useful, but as of now, the concept is better than the execution. Not trying to be critical -- just sharing my experiences in case you are interested.

One other suggestion: I think it would be helpful to have some audio feedback, like a soft click or blip that tells you when you've held the key long enough to trigger the long press. That would allow you to press it only as long as needed and not have to hold it overly long in fear of sending the regular key instead, which just creates a mess.
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

Re: long press

29 Jan 2017, 16:49

boiler wrote: For this to work properly, rather than sending the character first then backspacing, it should "eat" the keystroke and determine if it is a long press or not. If it is, then do the long press, then if it's not, it can send the normal key through. It should work that way even for a normal keypress like replacing 1 with ! when you long press 1. I don't want to see it type a 1 before replacing it with a !. It should wait until I release the key then type a 1 or ! depending on how long I held the key.
all the hotkeys are set using the ~ tilde/pass-through option because having to wait 240 ms to decide would slow down any regular typing too much.
taking out the tilde option means all your other hotstrings will stop working so thats not really an option either. ive tried this a few different ways at this stage and this is the only one where all 3 things work.

boiler wrote: If I change it to a very long number to represent several seconds (basically saying I never want it to spam so I don't have to be too precise on my long press duration), it didn't work.
i never intended it to be used for stopping the key from spamming though. if that number needs to be changed the it would probably be around the same value, 600 or 700 at the most maybe, but im not even sure how much it varies between computers or different types of hardware. that main purpose of that number is to not send any alternate keys once the key has started spamming, otherwise when you let go it will send the alternate key at the end like this: 555555555555555%

feel free make your own version from this that disables the keys from spamming. i wanted to have the option to do both so thats why i didnt do it like that.
boiler wrote: One other suggestion: I think it would be helpful to have some audio feedback, like a soft click or blip that tells you when you've held the key long enough to trigger the long press. That would allow you to press it only as long as needed and not have to hold it overly long in fear of sending the regular key instead, which just creates a mess.
yea thats not a bad idea. there is a bit of a knack to it unfortunately so something like that might help to get the hang of it when you use it first.



what about using the capslock key as the ctrl key anyway? its a bit easier to reach with your pinky and it pretty much on the home row

ctrl+ v should also work btw. not all hotkeys work though. i should have made that a bit clearer in the description
User avatar
boiler
Posts: 2607
Joined: 21 Dec 2014, 02:44

Re: long press

29 Jan 2017, 17:29

davebrny wrote:having to wait 240 ms to decide would slow down any regular typing too much
You don't have to wait the whole 240 ms to decide. As soon as the key is released, you act immediately and send the regular key if it's less than 240 ms. That doesn't slow down regular typing at all.
davebrny wrote:what about using the capslock key as the ctrl key anyway? its a bit easier to reach with your pinky and it pretty much on the home row
That's not a bad idea, but I currently use that for a different hotkey. It might be more handy as a control key, so maybe I'll try that.
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

Re: long press

29 Jan 2017, 18:46

ok. that sounded like a good idea but i tried it out and there still seems to be a slight delay, and typing two different letters quickly just ends up pasting the second key twice


try this out and youll see what i mean. maybe you have a better way of doing it.
the other problem with this is that removing the tilde means that hotstrings wont work and i cant think of how you would let the key spam happen after

Code: Select all

hotkey, $%ini_key%, long_press     ; line 42 of the script

Code: Select all

long_press:
stringTrimLeft, key, a_thisHotkey, 1  ; trim $ symbol
keyWait, % key
if (a_timeSinceThisHotkey < 240)
    send % "{" key "}"
else trayTip, , long press, 5
return
User avatar
Bon
Posts: 17
Joined: 11 Jan 2014, 07:31

Re: long press

30 Jan 2017, 12:53

How about

Code: Select all

keyWait, % key, T.240
; if (a_timeSinceThisHotkey < 240)
if !ErrorLevel
    send % "{" key "}"
else
    {
        SoundPlay *48
        trayTip, , long press
        keyWait, % key
        TrayTip
    }
Quidquid Latine dictum sit altum videtur
"Anything said in Latin sounds profound"

Return to “Scripts and Functions”

Who is online

Users browsing this forum: andylysm and 39 guests