• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

listen to different keys simultaneously

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have written a key listener for the keypressed event. the problem is that when a key is pressed and held the listener does not respond to any other key pressed. i want different keys recognized independently and simultaneously.how should i use multithreading and event handling in this case?
kindly note that i am using awt package in an applet.
waiting for your reply
kedar
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Kedar -
Threads won't help you -- because the AWT thread is the one responsible for handing out all of the key events -- but I think what you're trying to do is quite possible.
Look at the KeyListener interface again. If you implement the keyPressed and keyReleased methods, you will be able to figure it out when one key is pressed and another is also pressed before the first is released.
Dealing with the modifier keys (i.e., Ctrl, Shift, Alt) is even easier. InputEvent (the superclass of KeyEvent) has methods isShiftDown(), isAltDown() and so on.
One caveat here: I tested this in WinNT, JDK 1.2. Obviously, there might be bugs in other configurations (i.e., Java 1.1 in an applet) that could prevent it from working properly...
 
reply
    Bookmark Topic Watch Topic
  • New Topic