rvaiya / keyd

A key remapping daemon for linux.
MIT License
2.97k stars 175 forks source link

add possibility to do `keyd do` without any additional modifiers #432

Open ces42 opened 1 year ago

ces42 commented 1 year ago

Would it be possible to add a feature that is analogous do keyd do but ignores any active modifiers? What I mean is to add a function, say "nomoddo" so that if I'm (physically) holding alt and then the command keyd nomoddo C-v is run keyd will lift alt, press ctrl, tap v, lift ctrl and then press alt again, same as when I have a binding like

[alt]
<something> = C-v

Use case Many use cases for key remapping involve entering large amounts of text into programs (e.g. predetermined phrases, things like the current date+time, or scripts that copy the current mouse selection, modify it in some way and insert it back). The only easy way to do this seems to be to use the clipboard. The only (somewhat) reliable way to paste from the clipboard is to send ctrl+v or shift+insert to the program, which can be easily done with keyd do C-v. Now the problem is that if I bind this action to something like alt+a then alt will still be pressed when the action triggers and nothing gets pasted.

tkna91 commented 1 year ago

Can you do it with the following?

[alt]
a = macro(esc 100ms C-v)
ces42 commented 1 year ago

@tkna91 I'm confused. The example you provide will paste the clipboard (in most applications), same as

[alt]
a = C-v

(this will generate a alt up event before sending the control down event and re-press alt at the end of the macro). What I'm looking for is a way to use keyd to produce control+v from a script, regardless of what other modifiers are pressed.

tkna91 commented 1 year ago

Sorry if my guess is off. Are you saying that you want a mode that combines the current 1 and 2 operations below, which would be 3?

  1. when the Alt key is pressed
    keyd virtual keyboard   0fac:0ade       leftalt down
    keyd virtual keyboard   0fac:0ade       leftcontrol down
    keyd virtual keyboard   0fac:0ade       leftalt up
    keyd virtual keyboard   0fac:0ade       leftcontrol up
    keyd virtual keyboard   0fac:0ade       leftalt down
    keyd virtual keyboard   0fac:0ade       leftalt up
  2. executed keyd do "C-v".
    keyd virtual keyboard   0fac:0ade       leftcontrol down
    keyd virtual keyboard   0fac:0ade       v down
    keyd virtual keyboard   0fac:0ade       v up
    keyd virtual keyboard   0fac:0ade       leftcontrol up
  3. want a mode like this when keyd do "C-v" is executed (merge 1 and 2)
    keyd virtual keyboard   0fac:0ade       leftalt down
    keyd virtual keyboard   0fac:0ade       leftcontrol down
    keyd virtual keyboard   0fac:0ade       leftalt up
    keyd virtual keyboard   0fac:0ade       leftcontrol up
    keyd virtual keyboard   0fac:0ade       leftcontrol down
    keyd virtual keyboard   0fac:0ade       v down
    keyd virtual keyboard   0fac:0ade       v up
    keyd virtual keyboard   0fac:0ade       leftcontrol up
ces42 commented 1 year ago

I think the way that keyd do currently works is good and shouldn't be changed. I proposing a variant, say keyd nomoddo, that would behave as follows: If keyd nomoddo C-v is called when no modifiers are currently active then you would get

keyd virtual keyboard   0fac:0ade       leftcontrol down
keyd virtual keyboard   0fac:0ade       v down
keyd virtual keyboard   0fac:0ade       v up
keyd virtual keyboard   0fac:0ade       leftcontrol up

same as keyd do C-v. However if you do keyd nomoddo C-v while the alt layer is active (most likely because the alt key is physically being pressed) you would get

keyd virtual keyboard   0fac:0ade       leftalt up
keyd virtual keyboard   0fac:0ade       leftcontrol down
keyd virtual keyboard   0fac:0ade       v down
keyd virtual keyboard   0fac:0ade       v up
keyd virtual keyboard   0fac:0ade       leftcontrol up
keyd virtual keyboard   0fac:0ade       leftalt down
rvaiya commented 1 year ago

The problem with this proposal is that the behaviour would depend on whether or not the keyboard is currently managed by keyd. keyd can't release keys on keyboards that it hasn't grabbed, so the script would not be portable.

For this particular application you should be able to use something like xclip -o, since most applications will automatically set the selection when you highlight text.

tkna91 commented 1 year ago

@ces42 Something like this might be an alternative for now.

[alt]
a = macro(500ms C-v)
#!/bin/bash
FILE=/tmp/file
date > $FILE

#X11
xclip < $FILE
#Wayland
#wl-copy < $FILE
sleep 0.5
keyd do C-v