Ubuntu – Xbindkeys won’t work properly


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:

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.

Best Answer

  • 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
  • Related Question