keyd icon indicating copy to clipboard operation
keyd copied to clipboard

[Feature Request] add new action "layert(...)" for the timed layer activation with optional action afterwards

Open dimon40001 opened this issue 2 months ago • 2 comments

Hi,

I'm trying to make a "double-click"/double-press behavior using keyd. For instance, tap a button twice to trigger some action or shortcut. Use case:

  • Quickly pressing LeftShift, Leftshift to activate a Command Palette in VSCode (similar to the behavior of IntelliJ IDE).
  • Make typing umlauts easier. E.g. typing quickly a,a will actually produce ä and o,o -> ö.

Would it be possible to add a new Action, say layert(<layer>, <milliseconds>, <action>) which will activate a layer for the given amount of time and after the milliseconds time passed will call an action (or do nothing).

I've built one solution which works well with Ctrl, Alt, Shift, Meta keys but for symbols I think it's impossible using current functionality. Any feedback is hightly appreciated. Maybe what I want can be implemented with the already existing functionality and "timed" versions of actions.

# Simulation of Shift,Shift functionality with keyd
#
# Limitations: 
# Doesn't have any timeout or delay functionality.
# Leftshift then leftshift can be just typed consequently with arbitrary time in between

[ids]
* 

[main]

leftshift = overload(shift, oneshot(shift-shift))

[shift-shift]

#send shortcut for "Command Palette", Help or anything we want for double-press
leftshift = f1 

# - symbol keys will type "as is" returning the layout to main
# - control keys are overloaded to allow exit from the shift-shift layer on short press 
# and on long press will produce their default behavior (because pressing control keys 
# by default doesn't reset the layer to main)
rightshift = overload(shift, clear())
alt = overload(alt, clear())
control = overload(control, clear())
meta = overload(meta, clear())

dimon40001 avatar Sep 29 '25 14:09 dimon40001

Variants of this have been discussed, see for example https://github.com/rvaiya/keyd/issues/879 (perhaps there is one that more closely matches your use case), but I don't remember if there's one specifically tackling double-tapping letter keys.

For now, you've already discovered the overload(shift, oneshot(shift-shift)) pattern.

For the letter keys, I see two approaches with current functionality. The first is to use oneshotm(layera, a) and emit macro(backspace ä) when pressing a again in layera. I dare not elaborate the second one, but it involves setting a timeout on the tap action of an overload (as in the issue linked above) and emitting two letters in the hold layer.

In either case there are drawbacks, and I'm not sure whether it would be ergonomical. For starters, when you type 'aah' in frustration, it would turn into 'äh'. Whether that lessens or heightens the despair probably depends on your personality.

Would the first approach be good enough for your use case?

On September 29, 2025 4:46:30 PM GMT+02:00, Dmitry @.***> wrote:

dimon40001 created an issue (rvaiya/keyd#1122)

Hi,

I'm trying to make a "double-click"/double-press behavior using keyd. For instance, tap a button twice to trigger some action or shortcut. Use case:

  • Quickly pressing LeftShift, Leftshift to activate a Command Palette in VSCode (similar to the behavior of IntelliJ IDE).
  • Make typing umlauts easier. E.g. typing quickly a,a will actually produce ä and o,o -> ö.

Would it be possible to add a new Action, say layert(<layer>, <milliseconds>, <action>) which will activate a layer for the given amount of time and after the milliseconds time passed will call an action (or do nothing).

I've built one solution which works well with Ctrl, Alt, Shift, Meta keys but for symbols I think it's impossible using current functionality. Any feedback is hightly appreciated. Maybe what I want can be implemented with the already existing functionality and "timed" versions of actions.

# Simulation of Shift,Shift functionality with keyd
#
# Limitations: 
# Doesn't have any timeout or delay functionality.
# Leftshift then leftshift can be just typed consequently with arbitrary time in between

[ids]
* 

[main]

leftshift = overload(shift, oneshot(shift-shift))

[shift-shift]

#send shortcut for "Command Palette", Help or anything we want for double-press
leftshift = f1 

# - symbol keys will type "as is" returning the layout to main
# - control keys are overloaded to allow exit from the shift-shift layer on short press 
# and on long press will produce their default behavior (because pressing control keys 
# by default doesn't reset the layer to main)
rightshift = overload(shift, clear())
alt = overload(alt, clear())
control = overload(control, clear())
meta = overload(meta, clear())

-- Reply to this email directly or view it on GitHub: https://github.com/rvaiya/keyd/issues/1122 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

nsbgn avatar Sep 29 '25 15:09 nsbgn

Variants of this have been discussed, see for example #879

I will experient and check the full discussion later. Thank you so much for a good reference.

As a quick finding I have found the Global variable to be very useful in my scenario. I have not thougth about it since the documentation seems to have some ambiguity:

*oneshot_timeout:* If non-zero, timeout a oneshot layer
	activation after the supplied number of milliseconds.
	(default: 0)

Must be rather saying "... timeout a oneshot layer activation for the duration of the supplied number of milliseconds". The current wording means to me that the delay happens before the layer activation which is not the case.

Having this useful Global variable at hands I will try to experiment further with the already existing "timed" Actions.

P.S. typing "aah" vs. "äh" could really be an issue but it is subject to fine-tuning the delay configuration as per user preferences. I travel a lot in Europe and having US English keyboard and ability to type umlaus from time to time is more valuable than typing aah each time properly. I would then rather press-and-hold to type "aaaaaaaah!" if I wanted let's say to put a highly emotional comment on a social network.

dimon40001 avatar Sep 29 '25 16:09 dimon40001