Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] Keyboard input and the Swing Timer Class


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 February 2000 - 09:53 AM

I am attempting to perform certain actions in my game based on the combinations of the keys currently pressed on the keyboard. The event method of detecting keyboard input doesn''t seem to be what I need in that I need to be able to detect two or more keys pressed simataneously; not merely a key with a modifier (such as shift, alt, and control). As an example I need to able to detect that the ''up arrow'', the ''left arrow'' and any other letter key are pressed at the same time. I fire off my detection method based on a Swing Timer, but I do not know how to determine the current state of the keyboard in this method. The concept seems simple enough (I have implemented it in DirectX) but I can not find any references or posts on how to do this. Is my basic concept off here? I would appreciate any pointers some one could provide. Thanks,

Sponsor:

#2 joeG   Members   -  Reputation: 172

Like
Likes
Like

Posted 25 February 2000 - 10:21 AM

Since the API exposes the keyPressed and keyReleased events, I''m sure that they come to your event handler, regardless of whether another key is pressed down at the same time or not. Because of this it looks like you''ll have to queue events up in a set or something to that order.

JoeG

#3 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 February 2000 - 04:34 PM

I was afraid of that...

Thanks for the direction - you have saved me from wasting my time on a dead end...

#4 javanerd   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 February 2000 - 10:50 PM

Why on earth are you talking about event queues in this case :o ?

In order to read the keyboard from the Swing thread and to be able to detect multiple simultaneous keys down, you''ve just got to have four flags (fUp, fDown, fLeft & fRight). Then in your keyDown and keyUp handlers you modify these flags according to received events. And in the Swing timer triggered part of your code you read these flags and act appropriately.

Simple, eh?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS