0

How can I get the DEL char from keyboard?

If I use the I/O API I must wait the return to get the char but so I always get the ASCII code 10 or 13...

Thanks.

xdevel2000
  • 20,780
  • 41
  • 129
  • 196

1 Answers1

0

Use key Listener.

 public void keyTyped(KeyEvent ke)
    {
    if(ke.getKeyChar()== ke.VK_DELETE)
      {
    //do something
      }
    }

Here is a tutorial how you can do that.

nebula
  • 3,932
  • 13
  • 53
  • 82
  • Thanks, but I have to use the console. – xdevel2000 Dec 09 '11 at 08:51
  • I don't think you can do that from console because you have to hit ENTER to get anything from console. – nebula Dec 09 '11 at 08:54
  • Use Java [Scanner](http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html) . It can get characters but i doubt about keys like del. – nebula Dec 09 '11 at 09:18
  • @xdevel2000, what do you intend to do by intercepting DEL? – st0le Dec 09 '11 at 09:20
  • @st0le, I intend make something like InputStreamReader cin = new InputStreamReader(System.in); cin.read(); and have the ASCII value of DEL key. – xdevel2000 Dec 09 '11 at 12:38
  • @xdevel2000, Don't re-invent the wheel.... Use `Scanner` or a `BufferReader` (has readLine()) function...it'll handle the DEL key aswell. – st0le Dec 10 '11 at 04:40