Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9101001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:00:29+00:00 2026-06-17T01:00:29+00:00

I have a KeyBinding for my Java game, where I use the meta key

  • 0

I have a KeyBinding for my Java game, where I use the meta key and the Z key to move to the left.

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

How do I write the release form of this?

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

I’ve already tried

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

but to no avail, and have tried changing the KeyEvents to keycodes (int).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:00:30+00:00Added an answer on June 17, 2026 at 1:00 am

    Try using…

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

    Updated with working example

    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);
            }
        }
    }
    

    Note, I’ve never seen KeyEvent.META_DOWN_MASK work on Windows…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code here to create a key binding: KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_F1,
I have this xaml code: <Window.InputBindings> <KeyBinding Command={Binding Path=KeyEnterCommand} Key=Enter /> </Window.InputBindings> and that's
I have this xaml: <DataGrid.InputBindings> <KeyBinding Key=a Command={Binding Path=Function} CommandParameter={Binding ElementName=dataGrid1,Path=SelectedItem}></KeyBinding> <KeyBinding Key=s Command={Binding
I have a KeyBinding with the Key set to D1 which is the 1
I have this in MainWindow.xaml : <Window.InputBindings> <KeyBinding Key=O Modifiers=Control Command={Binding OpenCommand} /> <KeyBinding
This is what I need - have a key that will create ctags of
I primarily use Visual Studio and ReSharper (R#) for development and have excellent working
Previously, using the ALT+COMMAND+R key combination after highlighting a variable name in a Java
I currently have the following keybinding in my .vimrc : nnoremap <Leader>gs :Gstatus<Enter><C-n> I'm
I have made accelerators in my java gui by using setAccelerator(), and they work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.