xdotool press key by keycode (press option key)

15,762

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.

Share:
15,762

Related videos on Youtube

Tony Vlcek
Author by

Tony Vlcek

Student. Programmer in PHP using Nette Framework. Experiences with JavaScript (jQuery), C\C++.

Updated on September 18, 2022

Comments

  • Tony Vlcek
    Tony Vlcek over 1 year

    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 :)

    • Jacob Vlijm
      Jacob Vlijm about 7 years
      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).
    • Tony Vlcek
      Tony Vlcek about 7 years
      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
      Tony Vlcek about 7 years
      Okay, cool it works. However I can't get under 0.5s with the first media key press. But it still helps.