FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   keyboard focus
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: keyboard focus  (Read 281 times)
maniere


keyboard focus
« on: Mar 27th, 2004, 6:07am »

I haven't been able to figure out how to make sure my applets have keyboard focus once they load in their webpage.  Does anyone know a good way to do this?  A way that will work in all browsers and the most popular versions of the JRE?
 
thanks!
 
toxi_
Guest
Email
Re: keyboard focus
« Reply #1 on: Mar 27th, 2004, 1:02pm »

here's one approach to achieve just that:
http://www.toxi.co.uk/blog/2004_01_01_archive.htm#107330451700744369
 
hth!
 
maniere


Re: keyboard focus
« Reply #2 on: Mar 27th, 2004, 10:40pm »

hey that works great!  Or at least it works great if you are using the P5 keyPressed() listener....
 
But I want to accept keyboard input from the ESC key, and P5 does not yet seem ready to handle that.  I notice keyCode listed in the reference, but it's not yet implemented(?).
 
So I've turned to pure Java to check for key events.  And for some reason, even while your code gives the applet focus, the keyboard doesn't have focus until after any key is pressed once.  Then it responds to the second keypress.
 
Here is the code I am using:
 
public void keyPressed(KeyEvent e) {
  int code = e.getKeyCode();
  // if ESC key is pressed
  if(code == 27) {
    doStuff();
  }
  else {
    doOtherStuff();
  }
}
 
So I'm torn....  Your code resolves the keyboard focus issue if I use the P5 keyPressed listener, but I don't have access to all the keys I want.  Meanwhile the Java keyPressed() listener gives me all the access I need, but the keyboard focus issue resurfaces.
 
Any idea why this is happening?  Know of a workaround?  Any estimates when keyCode will be implemented in P5?  Or is it implemented already and I'm not using it correctly?
 
Thanks very much!
« Last Edit: Mar 27th, 2004, 10:58pm by maniere »  
Pages: 1 

« Previous topic | Next topic »