why ain't my keyboard left/right/up/down button respond?

why can't VK_left work for left button on the keyboard?(same apply to othe 3 direction button)please show me the proper code to use the direction button....
[171 byte] By [ckminga] at [2007-9-28 6:24:37]
# 1
Read the api.
Kayamana at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...
# 2
try KeyEvent.VK_LEFTjava is case sensitive
Woogleya at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...
# 3
nope.... KeyEvent.VK_LEFT can't wok.....the api also say the same thing but it's just won't work...maybe i miss out some thing.....currently i using KeyEvent.VK_A for the left button
ckminga at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...
# 4
How are you using it? Post the **** code.
Kayamana at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...
# 5
addKeyListener(new KeyAdapter() {public void keyPressed(KeyEvent ev) {char c = ev.getKeyChar();if(c==KeyEvent.VK_LEFT) { //perform stuff here................but can't read the VK_LEFT}}});
ckminga at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...
# 6

Here's your problem:

char c = ev.getKeyChar();

That should read:

int c = ev.getKeyCode();

The reason is that the ASCII code and the keyboard code MAY coincide for letters, but it won't coincide for control characters (which are not part of the ASCII spec). You have to test the key code (the integer generated by the keyboard) if you wish to get anywhere.

jbanesa at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...
# 7
You'll also thank yourself later if you use ActionMap and InputMap from the get-go...
bh94704a at 2007-7-9 17:36:34 > top of Java-index,Other Topics,Java Game Development...