How do you refer to the mac command key in the String version of Java's KeyStroke.getKeystroke?

自古美人都是妖i 提交于 2019-12-08 05:33:59

问题


The documentation for KeyStroke.getKeystroke(String) (e.g., getKeyStroke("control DELETE")) does not provide an example of how to access the macintosh command key, and I can't find a reference that lists the spellings of the various words for modifiers like "control" that this function accepts. What is the syntax for the command key?

For reference, here's the documentation for getKeystroke:


Parses a string and returns a KeyStroke. The string must have the following syntax:

<modifiers>* (<typedID> | <pressedReleasedID>)
  modifiers := shift | control | ctrl | meta | alt | altGraph
  typedID := typed <typedKey>
  typedKey := string of length 1 giving Unicode character.
  pressedReleasedID := (pressed | released) key
  key := KeyEvent key code name, i.e. the name following "VK_".

If typed, pressed or released is not specified, pressed is assumed. Here are some examples:

  "INSERT" => getKeyStroke(KeyEvent.VK_INSERT, 0);
  "control DELETE" => getKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);
  "alt shift X" => getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);
  "alt shift released X" => getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);
  "typed a" => getKeyStroke('a');

回答1:


I had to go to the source code for AWTKeyStroke getAWTKeyStroke(String s) to see all of the acceptable modifier terms, and then do a little trial and error, to check that the modifier syntax for the command key is "meta".



来源:https://stackoverflow.com/questions/17582640/how-do-you-refer-to-the-mac-command-key-in-the-string-version-of-javas-keystrok

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!