简体   繁体   English

在Java(OSX)中设置三个按钮加速器快捷键

[英]Setting three button accelerator key hot keys in Java (OSX)

I am trying to change a few hot-keys in the java application I am wokring on and it seems that the system I am using may not work with three button key combinations. 我正在尝试更改正在唤醒的Java应用程序中的一些热键,似乎我正在使用的系统可能无法与三个按钮组合一起使用。 We currently have a JMenuItem item and we set the hotkey with a call like this: 当前,我们有一个JMenuItem项目,并通过如下调用设置热键:

menuItem.setAccelerator(getAcceleratorKey(accelerator));

And here is the getAcceleratorKey method: 这是getAcceleratorKey方法:

    private KeyStroke getAcceleratorKey(int keyCode) {

    return KeyStroke.getKeyStroke(
                    keyCode,
                    Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
                    false);
}

It seems that the keyCode that this method takes as a parameter can only be one key pressed with command. 看来,此方法作为参数的keyCode只能是用Command键按下的一个键。 So how then would I do something like Command-shift z for undo? 那么我该如何做像Command-shift z这样的撤消操作呢? Do I need to use a different class? 我需要使用其他课程吗?

KeyStroke.getKeyStroke() takes modifiers as a parameter. KeyStroke.getKeyStroke()将修饰符作为参数。 A combination of them should give you what you want: 它们的组合应该给您您想要的:

KeyStroke.getKeyStroke(keyCode, 
  java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.META_MASK);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM