Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
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 3741 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 :
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.



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

JGO Ninja

Medals: 71

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
Offline Renoria

Junior Devvie


« 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

« JGO Spiffy Duke »

Medals: 40
Projects: 4
Exp: 7 years

« 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  

hadezbladez (1153 views)
2018-11-16 13:46:03

hadezbladez (520 views)
2018-11-16 13:41:33

hadezbladez (1178 views)
2018-11-16 13:35:35

hadezbladez (265 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (2808 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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 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!