Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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  
  A question out of curiousity  (Read 2497 times)
0 Members and 1 Guest are viewing this topic.
Offline Del-ONE

Senior Newbie





« Posted 2008-12-08 06:37:51 »

I just ran into something that might be strange.

Since switching over to ubuntu, I've haven't done anything directly within a KeyListeners methods, so this is the first chance I've had to notice something that is possibly different from java under Windows.  The thing is; I can't check it myself.

When I run the program and hold down a key, the system begins firing both keyPressed() and keyReleased() continuously.  However, the way I remember it from the last time I needed to know this (under Windows), the system would only keep performing keyPressed() while the button was held, and its seems like some old code is meant to work like that (and it did do what I needed it too).  So I'm wondering if this really is a difference, or am I just insane?
Offline anemian

Junior Newbie





« Reply #1 - Posted 2008-12-10 02:16:58 »

Yes it's different from what it does on all the window machines I use.
Offline cghislai

Junior Newbie





« Reply #2 - Posted 2008-12-24 00:26:55 »

Youre right.

If I remember, its KDE wich fires these KeyPressed/KeyReleased event for autorepeat.
You can use something like this to know how long a key has been hold down :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
protected long leftKeyTimer = 0;
protected long leftKeyFinalTimer = 0;

// On Key Press Event:
if (leftKeyTimer == 0) {
    leftKeyTimer = System.currentTimeMillis();
}
// On Key Release Event:
leftKeyFinalTimer += (System.currentTimeMillis() - leftKeyTimer);
leftKeyTimer = 0;

// When you update your game logics:
if (leftKeyTimer != 0) {
    leftKeyFinalTimer += (System.currentTimeMillis() - leftKeyTimer);
    leftKeyTimer = System.currentTimeMillis();
}
long leftTime = leftKeyFinalTimer;
leftKeyFinalTimer  =0;
// use leftTime here


The thing is you cant rely on key release event to know when a key has been really released. If it has not been really released, a keyPress event is fired right after the KeyRelease one.
So you might also try to wait sonething like 10ms (you should check how really close in time these 2 events are fired) when you receive a keyRelease event before processing it and cancel it if a keyPress event is received during this time.

Regards,

Charly

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

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #3 - Posted 2008-12-24 03:53:01 »

Has this bug still not been fixed  Huh

It's been there since 1.1, more than a decade!  Huh

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Renoria

Junior Duke




...


« Reply #4 - Posted 2008-12-24 06:00:58 »

Has this bug still not been fixed  Huh

It's been there since 1.1, more than a decade!  Huh

o.O! wtf I don't have this problem...
Offline pjt33
« Reply #5 - Posted 2009-01-20 20:14:01 »

Youre right.

If I remember, its KDE wich fires these KeyPressed/KeyReleased event for autorepeat.
Yes. Thanks: I've disabled it in KDE and now I'm going to go back to the 4k competition entries which were giving me key handling problems to see whether they're any better.
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.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
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!