ktrl icon indicating copy to clipboard operation
ktrl copied to clipboard

Make TapHold independent of any timeout?

Open canadaduane opened this issue 4 years ago • 1 comments

I'm just poking around the edges of ktrl at the moment (nice work!) and I have a question/suggestion:

It seems to me that the dual function of a tap/hold key need not be dependent on the length of time the key is held down.

Example use case:

  • consider the "CapsEscCtrl" setup, where "CapsLock is Escape when tapped, but Ctrl when pressed in combination with another key"
  • Sometimes I press CapsLock with the intent to follow up with a key combination (i.e. use it as Ctrl) but then hesitate if I've forgotten the correct completion for the combo. I don't want my "unintentional hesitations" to determine the key state for CapsEscCtrl.

One or two of the other keyboard event mappers I've seen (notably interception) works by waiting to see if a second key is pressed before the first is released. Here's how it might work:

  1. If the user presses CapsLock (KEYDOWN), then releases CapsLock (KEYUP) with no intervening KEYDOWN events, then this is a "tap", therefore it should simulate Escape (KEYDOWN/SYN/KEYUP).
  2. If the user presses CapsLock (KEYDOWN), then presses another key (e.g. KEYDOWN "C") before the CapsLock KEYUP event, then this is a "hold", therefore it should simulate Ctrl+C (Ctrl KEYDOWN/SYN/"C" KEYDOWN/SYN/"C" KEYUP/Ctrl KEYUP).

This way, the user need not think about whether they've reached a certain time threshold. Is this reasonable? Has it already been covered by ktrl but I didn't notice?

canadaduane avatar Aug 02 '21 04:08 canadaduane

Hey Duane! Thanks for reaching out :)

Admittedly I've become a bit rusty (pun-intended :P) as far the codebase goes. I haven't been maintaining it for the last few months.

With that said, I gave a quick glance at the relevant module again. The logic is mostly implemented here - tap_hold.rs

I believe that it currently only takes into account the "TapHold period".

I.E in the Ctrl-C scenario you described above, the output will be determined by the amount of time that passed between you pressing CapsLock and pressing C. If it's greater than the TapHold period, it'll register CapsLock as Ctrl. If it's lesser, it'll register it as Esc. After registering Ctrl/Esc it'll immediately follow that up with the C press event.

Also, note that ktrl is only triggered by input events (and not by timer events). Thus, the TapHold period is calculated each time a key event happens (and not via, for example, a timeout event).

Finally, if you'd like to tweak this behavior, feel free to open a PR. Of course, we'd probably want this functionality to be configurable :)

ItayGarin avatar Aug 03 '21 06:08 ItayGarin