Ubuntu – xdotool press key by keycode (press option key)

keyboardshortcut-keysshortcutsxdotool

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 🙂

Best Answer

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.

Related Question