14

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.

Ello
  • 281

6 Answers6

8

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
midenok
  • 848
  • 1
  • 10
  • 15
8

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.

Michaël
  • 180
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.

Ello
  • 281
2

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
1

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.

terdon
  • 104,119
0

Slightly updating this excellent answer, with ijkl Autohotkey-style substitution on Linux:

1.Install packages

sudo aptitude install xbindkey xdotool

2.Create template rc file

xbindkeys -d > ~/.xbindkeysrc

3.Put following into ~/.xbindkeysrc

# Alt+i => Up
"xset r off; xdotool keyup --window 0 i key --clearmodifiers --window 0 Up; xset r on"
  Alt + release+i

4.Restart xbinkeys

pkill -HUP xbindkeys

5.Hit Alt+i to check it out, should work in any application

Kirill
  • 111