• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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...
 
Hey! You're stepping on my hand! Help me tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic