gpt4 book ai didi

java - 使用 Metamask 释放按键绑定(bind)

转载 作者:行者123 更新时间:2023-12-02 00:03:57 26 4
gpt4 key购买 nike

我的 Java 游戏有一个 KeyBinding,我使用元键和 Z 键向左移动。

i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 4), "Z");
m.put("Z", sprite_moveLeft);

如何撰写此授权书?

i.put(KeyStroke.getKeyStroke(???????), "rZ");
m.put("rZ", sprite_rmoveLeft);

我已经尝试过了

i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 4), "Z");
m.put("Z", sprite_moveLeft);
i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 4, true), "rZ");
m.put("rZ", sprite_rmoveLeft);

但无济于事,并尝试将KeyEvents更改为键码(int)。

最佳答案

尝试使用...

KeyStroke.getKeyStroke(int keyCode, int modifiers, boolean onKeyRelease)

已更新工作示例

public class KeyBindingsTest {

public static void main(String[] args) {
new KeyBindingsTest();
}

public KeyBindingsTest() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
}

JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new KeyBindingPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}

public static class KeyBindingPane extends JPanel {

private JTextArea textArea;

public KeyBindingPane() {
setLayout(new BorderLayout());
add(new JScrollPane((textArea = new JTextArea())));

InputMap im = getInputMap(WHEN_IN_FOCUSED_WINDOW);
ActionMap am = getActionMap();

im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.ALT_DOWN_MASK, false), "Released");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.ALT_DOWN_MASK, true), "Pressed");

am.put("Released", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("released");
textArea.append("Released\n");
}
});
am.put("Pressed", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("pressed");
textArea.append("Pressed\n");
}
});

setFocusable(true);
requestFocusInWindow();
}

@Override
public Dimension getPreferredSize() {
return new Dimension(100, 100);
}
}
}

注意,我从未见过 KeyEvent.META_DOWN_MASK 在 Windows 上工作...

关于java - 使用 Metamask 释放按键绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14265467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com