Results 1 to 2 of 2
  1. #1
    Echilon Guest

    Default Run method on Ctrl+Shift+D

    I'm trying to create add a debug menu when the user presses Ctrl+Shift+D. I have a class which extends JFrame, and this is the code I'm using.

    Java Code:
    KeyStroke debugKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK & InputEvent.SHIFT_DOWN_MASK, false);
            Action debugAction = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    someMethod();
                }
            }; 
            this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(debugKeyStroke, "D");
            this.getRootPane().getActionMap().put("D", debugAction);
    I have another action set up to close the window when Escape is pressed which works perfectly, but I can't get this one to work.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    The masks are ored (bitwise-ored) together. You had them anded together. See Method Detail in KeyStroke api.
    Java Code:
    KeyStroke debugKeyStroke =
        KeyStroke.getKeyStroke(KeyEvent.VK_D,
            InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, false);

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. Open type (Ctrl-Shift-T) does not find types
    By Zhenya_Merom in forum Eclipse
    Replies: 2
    Last Post: 11-04-2009, 10:15 AM
  3. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 01:23 PM
  4. How to add hotkey(Ctrl+VK) to a button?
    By rpwtdj in forum Advanced Java
    Replies: 5
    Last Post: 01-10-2008, 02:13 AM
  5. how to issue the command of Ctrl-C (copy) in Java
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-18-2007, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •