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.

5
  • 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.
    – terdon
    Apr 26, 2014 at 14:31
  • Did you ever figure out how to get xdotool to repeat the key while held down?
    – Farzher
    May 9, 2014 at 4:04
  • 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.
    – Ello
    May 9, 2014 at 11:37
  • 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
    – BurninLeo
    Sep 5, 2014 at 13:35
  • Looks like you're trying to simulate a German keyboard layout. Why don't you just switch your keyboard layout in the system settings?
    – Rapti
    Dec 8, 2015 at 19:04

6 Answers 6

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
2
  • 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.
    – Ello
    May 15, 2015 at 9:28
  • @Ello, these answers are not only for you, so the most universal solution is appreciated.
    – midenok
    Oct 21, 2015 at 12:21
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.

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.

2
  • 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.
    – terdon
    Apr 26, 2014 at 21:31
  • 1
    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.
    – wjandrea
    May 4, 2019 at 4:18
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.

4
  • 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
    – Ello
    Apr 26, 2014 at 13:05
  • i got it to work, but with something else
    – Ello
    Apr 26, 2014 at 13:15
  • @Ello great! What did you use? It worked fine for me. Could you post an answer explaining your solution and accept it?
    – terdon
    Apr 26, 2014 at 13:17
  • I altered my post, I can't answer my own questions because lack of reputation. Sorry
    – Ello
    Apr 26, 2014 at 13:20
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .