Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sxhkd + Xdotool key not working because of keyboard grab #86

Open
BenoitAverty opened this issue Oct 20, 2016 · 14 comments
Open

Sxhkd + Xdotool key not working because of keyboard grab #86

BenoitAverty opened this issue Oct 20, 2016 · 14 comments

Comments

@BenoitAverty
Copy link

Hello,

I am trying to bind the alt+right / left combination to End/Home key. Here's what I first tried:

alt + Right
  xdotool key End

alt + Left
  xdotool key Home

However, this doesn't work, and I'm guessing it's because sxhkd captures the keyboard when the combination is pressed, and thus the End / Home key are not sent properly to the active window.

Here's my workaround:

alt + Right
  xdotool keyup Alt_L+Right && xdotool key End

alt + Left
  xdotool keyup Alt_L+Left && xdotool key Home

This works, but causes weird/unintuitive behaviour because the keys are released even though they're phisycally pressed on my keyboard. Which means, for example, that if I want to press Home then End, I have to press alt+left, then release alt before pressing alt+right.

Is there a way to force sxhkd to release the keyboard as soon as a key combination is matched? Or another workaround?

What I also tried :

alt + Right
  xdotool keyup Alt_L+Right && xdotool key End && xdotool keydown Alt_L

But this is even worse because when I do alt+right then release, it's as if I typed End then Alt. This makes my hidden menus pop up for example.

Thanks in advance.

@louwers
Copy link

louwers commented Feb 5, 2017

xdotool key --clearmodifiers End

should work. It doesn't on my machine, but it should.

I think this might be a problem with xdotool.

@noctuid
Copy link

noctuid commented Feb 6, 2017

jordansissel/xdotool#105 is somewhat related. This happens even if the key isn't a modifier (e.g. F1; you need to send a keyup event for F1 before). Using @ for the non-modifier makes it work, but it will still act as if the modifier is held even with --clearmodifiers or keyup mod. The solution mentioned above doesn't work (keyup mod+key) at all for me; the modifier is still active.

@BenoitAverty
Copy link
Author

The --clearmodifiers solution has the same problem as what I currently have I think. I have to release alt to press it again if I want to type End then Home for example.

Or maybe it's another problem, can't remember. Bu I remember that I tried it and it didn't solve the problem.

@sandric
Copy link

sandric commented Oct 21, 2017

Any progress with that?

@joeytwiddle
Copy link

joeytwiddle commented Jan 12, 2019

I use xautomation's xte to clear the modifier, send the key, and then set the modifier again:

alt + Left
  xte "keyup Meta_L" "keyup Left" "key Home" "keydown Meta_L"

But that suffers the same problem as xdotool. When I finally release the Alt, the application (e.g. Firefox) recognises an Alt press, and opens the menus.

A workaround is to send an extra Alt press, to counteract our final Alt press:

alt + Left
  xte "keyup Meta_L" "keyup Left" "key Home" "keydown Meta_L" "keyup Meta_L" "keydown Meta_L"

Using this, I do occasionally see the menu bar flicker in Firefox, but it's mostly ok.


Another issue is that the binds above only work properly for the left Alt key.


To really solve this, I think we would need a layer higher up in X, which doesn't pass any keystrokes down to the applications until we have decided what we want to send. (So in this case, the application would never see the Alt key being pressed or released. It would only receive an End key event.)

(Ideally we would also be able to send different strokes depending on the focused application.)

Please let me know if you find such a thing!


Edit: The approach taken by kinto is to pro-actively remap the keyboard when different applications are focused. The remapping means that the original keystroke is never seen by the application receiving the keystroke. Note that kinto's goal is to make a PC keyboard feel like a Mac keyboard, which might not be your goal.

@simlei
Copy link

simlei commented Feb 8, 2019

I would also be interested in such a solution

@BlueDrink9
Copy link

xdotool and sxhkd seem to have a raft of incompatibilities. Getting them to play more nicely together (esp so that xdotool can retrigger sxhkd) would be very useful for working around sxhkd's foibles.

@da99
Copy link

da99 commented Jun 28, 2019

@BenoitAverty Did you ever find a solution to this? This worked for me:

alt + Right
  xdotool keyup Right key --clearmodifiers End
alt + Left
  xdotool keyup Left key --clearmodifiers Home

It's based on this answer: https://askubuntu.com/a/1136052/44640

I'm hoping one day I will get a programmable keyboard (QMK firmware compatible hopefully) and not have to deal with X11 and key daemons all together.

@mdynnl
Copy link

mdynnl commented Dec 2, 2020

~ on either one or both works
maybe both, so both keys get replayed
it depends on your needs

~alt + Right
  xdotool key End

if you're wondering about the ~, it's in the manual
maybe this issue can be closed now

@mdynnl
Copy link

mdynnl commented Dec 2, 2020

CHORD_i     := [MODIFIERS_i +] [~][@]KEYSYM_i

as per the syntax,
~alt shouldn't work, but it does ¯\_(ツ)_/¯

@lpanebr
Copy link

lpanebr commented May 15, 2022

I'm think my problem might be related.. The following works:

ctrl + shift + u
  xdotool mousemove_relative 3000 0

but if I try with super it does not: 🤔

super + u
  xdotool mousemove_relative 3000 0

I've tried the ~ modifier but nothing changes.

I's worth noting that I have bindings using super + letters for other commands and those work.

Any idea??

@blumberg
Copy link

blumberg commented Jul 2, 2022

I don't have much experience, but I was doing something similar and adding @ to the letter make it work

super + @u
  xdotool mousemove_relative 3000 0

Might worth a shot

@lpanebr
Copy link

lpanebr commented Jul 4, 2022 via email

@avidseeker
Copy link

I was trying to remap Print to menu key using:

Print
    xte "key Menu"

Which wasn't working (but typing the command in terminal works)

Adding sleep fixed the problem for me:

Print
    sleep 0.1 && xte "key Menu"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests