Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Keyboard input  (Read 2447 times)
0 Members and 1 Guest are viewing this topic.
Offline dbotha

Senior Newbie

« Posted 2010-11-15 18:24:16 »

Under Linux I receive multiple keyPressed & keyReleased events whilst a key is held down. Do any other operating systems exhibit this behaviour? I am considering working around this issue by detecting if the OS is Linux and then only considering a key as released after a given duration has elapsed and no new keyPressed events have arrived for the key. Is this likely to be a reliably work around? I imagine it will work perfectly under my setup however I am unsure how consistent the rate of arrival of keyPressed / keyReleased events is among other setups. I have previously used JInput however if I recall I had to set some permissions on my system for it to work correctly. I'd prefer to avoid going down this path if at all possible.

Thanks Smiley
Offline Abuse

JGO Ninja

Medals: 70

falling into the abyss of reality

« Reply #1 - Posted 2010-11-15 18:45:20 »

Has that behaviour still not been fixed?! I remember that bug being in Java 1.1!  Undecided

Just forget Linux  Roll Eyes
Offline Karmington

Senior Devvie

Medals: 1
Projects: 1

Co-op Freak

« Reply #2 - Posted 2010-11-15 19:51:00 »

'Please keep the 'A' key pressed down for 3...2...1..seconds. Thank you. We have now calibrated your keyboard. Please have a safe gaming experience.'

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dbotha

Senior Newbie

« Reply #3 - Posted 2010-11-15 20:17:43 »

Just forget Linux  Roll Eyes

I would but it's my OS of choice, it'd be nice to play my own game every now and then Wink I think I'll probably go down the calibration route as Karmington suggests. Do any another operating systems exhibit this behaviour, or is it just Linux?
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #4 - Posted 2010-11-17 14:53:38 »

It's been a while, but I think that the timestamps (InputEvent.getWhen()) of the extraneous keyUp/keyDown pairs have the same value, so you can filter them out.

Are you looking to perform some action on keyReleased, or is it sufficient just to maintain a boolean variable tracking key state? I've never seen problems with this.
Offline dbotha

Senior Newbie

« Reply #5 - Posted 2010-11-17 15:16:40 »

Thanks for the input ryanm, I'll take a look into getWhen(). I was actually looking to perform a game event only once no matter how long the key is held down for. If the key is released and then repressed this should trigger a second game event, etc. I think I pretty much solved the problem -- at least its working correctly on the three different Linux setups I run. Basically on Linux I maintain my own 'key state'. When a keyPressed event is received the associated key state is set to indicate pressed. When a keyReleased event is received a countdown timer is started, however if queried the key state is still considered pressed. If a new keyPressed event is received for the key before the timer expires the timer is cancelled. If the timer expires the associated key state is set to indicate released. Obviously you lose some granularity in that a key may be considered pressed for a little time after release, however for my game at least this is not noticeable in the slightest.
Offline ShannonSmith
« Reply #6 - Posted 2010-11-17 19:05:56 »

This has long been a painful problem on Linux that absolutely should have been fixed but was marked as not a bug. The reasoning being that KeyPressed/Released/Typed events are thin wrappers around OS events and this is just the way X11 does key events. This of course totally screws you if you need super-responsive key handling. The solution you describe is the only reliable one available without resorting to using a native lib.

Pages: [1]
  ignore  |  Print  

EgonOlsen (1295 views)
2018-06-10 19:43:48

EgonOlsen (1160 views)
2018-06-10 19:43:44

EgonOlsen (897 views)
2018-06-10 19:43:20

DesertCoockie (1301 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1337 views)
2018-04-24 18:14:32

ivj94 (2078 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2204 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!