Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding addKeyListener to an applet

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
GB
Hi. I'm creating an applet for a webpage and I need to detect for the keyboard primarily the arrowkeys. I have tried the following which doesnt seem to work:

public boolean keyDown(Event evt, int key) {
showStatus(String.valueOf(key));
return true;
}

so I have moved up to Java 1.1 and decided to use a KeyListener. How do I set this up so that a keypress is detected whenever the browser has focus?
I am also running a thread if that makes any difference.
Many thanks in advance.
ASCII silly question, get a silly ANSI
 
I don't think this has to do with Applet but more of the browser. When the browser loads up, the focus is ON your browser not your Applet even if your browser only contains the applet. Therefore when you press any keys, nothing is shown since the applet does not have the focus and all the event listeners would be inactive. Perhaps you could use javascript? or a more ugly way would be to click(mouse) on your applet first... If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top