Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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 1215 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 Knight


Medals: 14


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

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (73 views)
2014-11-26 15:22:04

toopeicgaming1999 (63 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (57 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!