Results 1 to 6 of 6
  1. #1
    Sainst is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Unhappy How to identify the up, down, left and right keys with the keylistener

    I Want to identify up, down, left and right keys with the keylistener()
    WHATE NAME DO I IDENTIFY IT WITH
    Last edited by Sainst; 04-09-2014 at 05:37 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: How to identify the up, down, left and right keys with the keylistener

    Please edit your post and restore the font to normal size.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Sainst is offline Member
    Join Date
    Apr 2014
    Posts
    7
    Rep Power
    0

    Default Re: How to identify the up, down, left and right keys with the keylistener

    OK

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: How to identify the up, down, left and right keys with the keylistener

    Do a Search here on the forum for lots of code samples that used keylisteners.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: How to identify the up, down, left and right keys with the keylistener

    One way to do it is to print the keyCode for the keys pressed - then you can look for a keyEvent with that code and handle it with something like a switch. This might work fine for basic things, but it isn't ideal. It's how I first figured it out in the long long ago. There are also static fields which represent the key codes - VK_LEFT, VK_RIGHT, etc... Take a look at the docs: KeyEvent (Java Platform SE 7 )

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,984
    Rep Power
    9

    Default Re: How to identify the up, down, left and right keys with the keylistener

    Shameless self-promotion: See the "detecting non-character keys" section here: Mouse and Keyboard Listeners - Tutorials - Static Void Games
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 0
    Last Post: 05-12-2013, 10:51 AM
  2. Replies: 1
    Last Post: 04-27-2012, 03:47 AM
  3. Reversing dojo slider to make it slide from right to left rather left to right as giv
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-05-2011, 01:49 PM
  4. square moves left and down but not up or left
    By natdizzle in forum AWT / Swing
    Replies: 3
    Last Post: 02-04-2011, 05:20 PM
  5. identify a thread
    By valery in forum Advanced Java
    Replies: 1
    Last Post: 07-25-2007, 01:24 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
  •