Search code examples
javaawtrobot

KeyEvent for the Mac Option key in Java Robot class?


I was wondering if there was a KeyEvent code for the Mac "Option" key within the java.awt.event.KeyEvent library. I'm trying to write a class for executing Mac OS specific shortcuts (i.e. SHIFT + OPTION + COMMAND + ESC), but I can't find the code for the Option key anywhere. Any help is appreciated!


Solution

  • Try logging it to find out it's keyCode and find the key with the same keycode as what you logged. In case logging doesn't help you out, try using ALT.

    From what I know, for all intents and purposes, Mac's option is usually the equivallent of ALT on Windows, and will probably end up resolving as VK_ALT

    EDIT: Upon further inspection, it seems that Option uses keycode 58 (http://macbiblioblog.blogspot.com/2014/12/key-codes-for-function-and-special-keys.html) and it seems you're out of luck, since the awt.event.KeyEvent doesn't cover that one...