Archived

This topic is now archived and is closed to further replies.

CPeX

[java] asci for arrows

Recommended Posts

does someone know the asci code for the arrows? or is there a better solution if you use Keyevents e e.getKeyChar(), I have tried to find the asci code myself but I get for the 4 arrows the same number 65535 ?!??

Share this post


Link to post
Share on other sites
I don''t believe that arrows are a standard ASCII code. You can check out this page[asciitable.com] for a nice big table of ASCII characters and the numbers associated with them.

-pirate_dau

Share this post


Link to post
Share on other sites
Try Event.LEFT, Event.RIGHT, Event.UP, Event.DOWN

These are all static int''s from the event class that define the value of those keys.

-Just when you think things are starting to look up, life grabs you by the jaws makes you open up wide and sh*ts down your throat.

Share this post


Link to post
Share on other sites
Or KeyEvent.VK_DOWN and KeyEvent.VK_UP and KeyEvent.VK_RIGHT and KeyEvent.VK_LEFT

For the numeric pad, KeyEvent.VK_KP_DOWN and KeyEvent.VK_KP_UP, etc. Cough, sorry about the other post somehow I had thought you were looking for an ASCII character that looked like this: ''->'' or something.

-pirate_dau

Share this post


Link to post
Share on other sites
e.getKeyChar() only displays printable characters. The arrows are not printable. They also do not generate an ascii code in the traditional sense. If you do programming in ''C'' you will notice that when you run printf("%d",getc()); in an infinite loop and press and arrow, it throws out a ''0'' first, then a second number representing the arrow key. The ''0'' is like an escape character. I don''t think you can pick up on this in Java.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites
Easy, just convert the char to an int and print the dam thing from a FRAME or JFRAME, but hay here are the values any way....

public static final int key_insert = 1025;
public static final int key_delete = 127;
public static final int key_home = 1000;
public static final int key_end = 1001;
public static final int key_pageup = 1002;
public static final int key_pagedown = 1003;
public static final int key_left = 1006;
public static final int key_right = 1007;
public static final int key_up = 1004;
public static final int key_down = 1005;
public static final int key_backspace = 8;

NOTE: you will have to detect your own controls and shifts at the key event level.

:-)

Share this post


Link to post
Share on other sites
As pirate_dau said, use the KeyEvent.VK_UP, etc.

To determine which of these keys was pressed use the getKeyCode() method instead of the getKeyChar() method (which only returns UNICODE characters).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, this won''t be much help for Java, but if anyone wants to know the good ol'' dos ascii codes for the arrow keys, here they are:

up: 0, 72
left: 0, 75
right: 0, 77
down: 0, 80

where 0 is the escape code (each key is two bytes instead of one)
it took me a long time to figure these out for my first QBasic game, but i''ve got them down pat now

Share this post


Link to post
Share on other sites