Hi everyone,
Does anyone know how do i detect that the backspace button
has been pressed by using the keylistener. What i mean is what do i put in
the keypressed method to know that the backspace button has been pressed?
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
Oliver Wong - 07 Sep 2006 20:22 GMT
> Does anyone know how do i detect that the backspace button
> has been pressed by using the keylistener. What i mean is what do i put in
> the keypressed method to know that the backspace button has been pressed?
The same way you'd detect any other key event. Just register a listener
for the event, and when a keyPressed() event occurs, examine the event to
see if it involved the backspace key. The virtual key code for backspace is
VK_BACK_SPACE.
(http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyEvent.html#VK_BACK_SPACE)
- Oliver
mikeboggs - 08 Sep 2006 03:30 GMT
I believe you will be able to do this:
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==e.VK_BACK_SPACE)
{
//do what you need to do
}
}
Should also work with VK_ENTER, VK_TAB as well, just for reference.
Hope this helps.
Michael Boggs