so I'm trying to make a keyboard shortcut using xdotool. The only thing that I'm missing and that can't find out how to do is this:

How to press the option key on my keyboard. In more general case, and this would solve my problem as well, how to press a key using xdotool based on keycode (if you know about other program which can do this, I don't mind using that instead).

I have a windows keyboard and there is this 'option button' (in between alt gr and right ctrl), when pressed it opens the right-click menu (right next to where the typing cursor is). I need to press this button in a script somehow. I found out (using showkey -k) that the keycode of this key is 127, but I can't make xdotool to press it.

Any ideas on how to do this?

PS: I know that I can simulate a right-click by xdotool click 3 but that doesn't help because the right click then occurs where the mouse pointer is and I need it to happen where the typing cursor is.

Thank you :)

  • 1
    Not sure how you tried, but see this: askubuntu.com/questions/872695/… you need a little break to prevent a combined keypres (virtual/real). 0.4 second should do. Please mention if this fixes it. Use the xev command to find out the key. ( xev + Return, then press your key). Apr 7, 2017 at 11:30
  • Thank you, that's probably what I've been looking for. I forgot that it's called the media key, so I've been searching for option key, kecodes, etc... I'll test it out.
    – Tony Vlcek
    Apr 7, 2017 at 12:04
  • Okay, cool it works. However I can't get under 0.5s with the first media key press. But it still helps.
    – Tony Vlcek
    Apr 7, 2017 at 13:07

2 Answers 2


Problem solved thanks to the comment from Jacob Vlijm.

The name of the button can be found this way: run xev, then press the button and the name shows up in the brackets. In my case it was this: keycode 135 (keysym 0xff67, Menu), here Menu is the name of the key.

Then I could run xdotool Menu. However to make it work with a custom shortcut I had to add sleep before it, so I ended up with this code:

sleep 0.5 && xdotool key 'Menu'
sleep 0.01 && xdotool key 's'
sleep 0.01 && xdotool key 'e'

and it works! :)

BTW: The purpose of this whole thing was to quickly switch between spelling languages in Chrome.


When adding a keyboard shortcut on Ubuntu 18.04 it is necessary to explicitly run a subprocess:

/bin/bash -c "sleep 0.4 && xdotool key Menu"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.