Xbindkeys won't work properly

11,075

Solution 1

The problem with xdotool is while real keys are pressed Xorg repeatedly sends keypress events (look at xev output). To overcome this you need to temporarily turn off repeat feature, then generate KeyRelease event on key that were down.

Instead of

"sleep 0.2 && xdotool type --delay 15 '{'"
  Control+Alt + 7

try the following:

"xset r off; xdotool keyup --window 0 7 type --clearmodifiers --window 0 '{'; xset r on"
  Control+Alt + 7

Solution 2

As documented in similar questions (Why do these xte commands work in terminal, but not when bound with xbindkeys?), you can ask xbindkeys to trigger events on release (on key up):

"xdotool key braceleft"
   Release+Control+Alt + 7

In this way, there is no conflict between the keys used for the shortcut and those sent.

Solution 3

As I tried another several things, i noticed that xdotool seems to trigger too soon. I altered the config like this:

"sleep 1 && xdotool type --delay 15 '{'"
Control+Alt + 7

NOW it sends the correct { sign to the active window. Now the only thing left is to reduce the sleep and delay to a workable value, because 1 second seems a bit too long :)

** Addition Info ** Well, now I managed to find suitable values. HOWEVER this only works if you release the keys until the sleep duration is over. If you are too slow if won't work.

This is my current config for all unconvenient german AltGr characters

"sleep 0.2 && xdotool type --delay 15 '{'"
Control+Alt + 7

"sleep 0.2 && xdotool key --delay 15 at"
Control+Alt + q

"sleep 0.2 && xdotool type --delay 15 '€'"
Control+Alt + e

"sleep 0.2 && xdotool type --delay 15 '['"
Control+Alt + 8

"sleep 0.2 && xdotool type --delay 15 ']'"
Control+Alt + 9

"sleep 0.2 && xdotool type --delay 15 '}'"
Control+Alt + 0

"sleep 0.2 && xdotool type --delay 15 '~'"
Control+Alt + plus

However if you want to type multiple @ signs (for example) you have to press Ctrl+Alt+Q as intended, but release all keys and then press it again. This, however is much, much better than not having the option Control+Alt instead of AltGr but it is not that effective as I was used too. Maybe I will find a solution for this too.

Solution 4

I recently had this issue, where I tried to simulate the media Play/Pause (XF86AudioPlay) key using Ctrl + G. After some research, it appeared not only do I need to cancel out the Control, but also the g key (which is what needed the sleep 0.1 delay to begin with). If I cancel out both of these keys by using keyup within xdotool as well as the --clearmodifiers switch, it works. This is my new command, in my .xbindkeys.rc file:

"xdotool keyup g key --clearmodifiers XF86AudioPlay"
Control + g

Solution 5

Not sure why it doesn't work with xbindkeys, I'm guessing you need to specify the window to write to. As a workaround, you can use xvkbd instead.

  1. Install xvkbd

    sudo apt-get install xvkbd
    
  2. Add this to your .xbindkeysrc file

    "xvkbd -text '{'"
    Control+Alt + 7
    

That should work.


NOTES

For some reason, on my machine, xvkbd is using one of my secondary layouts (Spanish) instead of my main one (US English) and this causes { to actually print ". If you also have this issue, just play around a bit to find out which key corresponds to { with the layout used. Alternatively, you can dig deeper and figure out where xvkbdgets its locale settings from.

Share:
11,075

Related videos on Youtube

Ello
Author by

Ello

Updated on September 18, 2022

Comments

  • Ello
    Ello almost 2 years

    I have bit of a problem. I wanted to remap some hotkeys I am used to from my previous system but I can't get it to work properly with xbindkeys.

    xbindkeys recognizes the combination but somehow the command does not trigger.

    If I use the command

    xdotool key braceleft
    

    It outputs me the correct { sign in the console. However if I use the same command in xbindkeys nothing happens. If I replace the command with firefox it works properly and opens firefox, so I guess xbindkeys works.

    I want to achieve the following:

    I want to type the character { to the active window with either Alt_R + 7 or Alt_Left+Ctrl+7 so I can use both. I know Alt_R (AltGr) is the proper way but on german keyboards it is somehow hard to type the braceleft with the AltGr (Alt_R) key so I HAVE to use Alt_L+Control+7 instead (like I was used to in my previous system). I somehow got it to work properly in 12.04, but I can't get it to work in 14.04.

    Any suggestions? I tried several commands. All of them worked in the console but none of them worked when executed by xbindkeys

    xdotool type '{'
    xdotool key braceleft
    xdotool key ISO_Level3_Shift+7
    xvkbd -xsendevent -text '{'
    xvkbd -xsendevent -text '\[Alt_R]+7'
    

    This is my config, which won't work

    "xdotool key braceleft"
    Control+Alt + 7
    

    However, this works:

    "firefox"
    Control+Alt + 7
    

    Solution Edit

    As I tried another several things, i noticed that xdotool seems to trigger too soon. I altered the config like this:

    "sleep 1 && xdotool type --delay 15 '{'"
    Control+Alt + 7
    

    NOW it sends the correct { sign to the active window. Now the only thing left is to reduce the sleep and delay to a workable value, because 1 second seems a bit too long :)

    ** Addition Info ** Well, now I managed to find suitable values. HOWEVER this only works if you release the keys until the sleep duration is over. If you are too slow if won't work.

    This is my current config for all unconvenient german AltGr characters

    "sleep 0.2 && xdotool type --delay 15 '{'"
    Control+Alt + 7
    
    "sleep 0.2 && xdotool key --delay 15 at"
    Control+Alt + q
    
    "sleep 0.2 && xdotool type --delay 15 '€'"
    Control+Alt + e
    
    "sleep 0.2 && xdotool type --delay 15 '['"
    Control+Alt + 8
    
    "sleep 0.2 && xdotool type --delay 15 ']'"
    Control+Alt + 9
    
    "sleep 0.2 && xdotool type --delay 15 '}'"
    Control+Alt + 0
    
    "sleep 0.2 && xdotool type --delay 15 '~'"
    Control+Alt + plus
    

    However if you want to type multiple @ signs (for example) you have to press Ctrl+Alt+Q as intended, but release all keys and then press it again. This, however is much, much better than not having the option Control+Alt instead of AltGr but it is not that effective as I was used too. Maybe I will find a solution for this too.

    • terdon
      terdon about 10 years
      Huh, that's a good find! There is no rep limit to answering your own question, only a time limit. It would be great if you could come back and post this as an answer in 6 hours. That will also give you some rep if you care about that. If you really don't care, I will just include your solution in my answer in a few days.
    • Farzher
      Farzher about 10 years
      Did you ever figure out how to get xdotool to repeat the key while held down?
    • Ello
      Ello about 10 years
      To be honest, I did not try it by now. I succesfully got League of Legends to run smooth with 60fps (in 12.04 it wouldn't start at all) so that I, when I am at home, I was playing the whole time.
    • BurninLeo
      BurninLeo almost 10 years
      I did not get some shortcuts working for days. The solution was simple: My Ubuntu desktop got the shortcuts before xbindkeys. Just edit the kayboard settings, add a new custom shortcut with action xdotool getactivewindow key Home
    • Rapti
      Rapti over 8 years
      Looks like you're trying to simulate a German keyboard layout. Why don't you just switch your keyboard layout in the system settings?
  • Ello
    Ello about 10 years
    still does not work. even with proper characters. if i write xvkbd -text 'apple' in the console, it prints apple, if i execute it via xbindkeys, nothing happens. if i look at xbindkeys -v it see it recognized the command pressed
  • terdon
    terdon about 10 years
    @Ello great! What did you use? It worked fine for me. Could you post an answer explaining your solution and accept it?
  • Ello
    Ello about 10 years
    I altered my post, I can't answer my own questions because lack of reputation. Sorry
  • terdon
    terdon about 10 years
    This is very strange, I'm glad you worked it out but I really can't figure out why it's happening. Anyway, thanks for taking the time to post this, it might help the next person with the same issue.
  • Ello
    Ello about 9 years
    Thank you for your reply, but I am using Manjaro with XFCE now and there it worked out of the box, so no sleep needed.
  • midenok
    midenok over 8 years
    @Ello, these answers are not only for you, so the most universal solution is appreciated.
  • wjandrea
    wjandrea about 5 years
    Instead of sleep, I think you want to add + release to the key combos. That will tell xbindkeys to wait until the key is release before triggering the command.