Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By doWhile

Thread: Key press not registering as ENTER

  1. #1
    trader5050 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

    Default Key press not registering as ENTER

    I have the following code:

    Java Code:
    optionWidth.addKeyListener(new KeyAdapter() {
                @Override
                public void keyTyped(KeyEvent e) {
                    super.keyTyped(e);
    
                    if (e.getKeyCode()==KeyEvent.VK_ENTER) {
    
                        System.out.println("Pressed ENTER");
    
    
    
                    } else {
                        System.out.println("Key was NOT enter");
                    }
    
                }
            });
    No matter what I do, ENTER (either on the numeric keypad or the standard one) is not registering as ENTER... Very odd, I think.

    Am I just missing something here?

    -Jason

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    Read the API for KeyEvent's keyCode method, it states
    For KEY_TYPED events, the keyCode is VK_UNDEFINED
    Use keyPressed to get the keyCode.
    Fubarable likes this.

  3. #3
    trader5050 is offline Member
    Join Date
    Nov 2010
    Posts
    10
    Rep Power
    0

Similar Threads

  1. Press enter to continue (Jpanel)
    By david522 in forum New To Java
    Replies: 10
    Last Post: 05-22-2011, 03:40 PM
  2. Command not registering.
    By Kuetsum in forum New To Java
    Replies: 3
    Last Post: 01-18-2011, 07:19 AM
  3. Registering problem
    By trini32 in forum New To Java
    Replies: 1
    Last Post: 06-25-2009, 04:35 AM
  4. Reading Char without needing to press enter
    By x0psci in forum New To Java
    Replies: 0
    Last Post: 11-23-2007, 04:28 PM
  5. Press any key to continue/press enter
    By JT4NK3D in forum New To Java
    Replies: 1
    Last Post: 11-17-2007, 09:27 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
  •