Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
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  
  keyreleased bug  (Read 1640 times)
0 Members and 1 Guest are viewing this topic.
Offline luisoft

JGO Coder

Projects: 6
Exp: 10 years

Java games rock!

« Posted 2003-03-05 15:23:42 »

I am developing a game in Java.
When I keep a directional key pressed (for my sprite in game keep running) sometimes an event keyreleased is thrown but I did not released the key! It occours in Linux but not in Windows...
I have found this link about the subject:

Does anyone knows how to overcome this problem?

Luiz Fernando
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #1 - Posted 2003-03-05 16:28:02 »


"It occours in Linux but not in Windows..."

did u tryed that with the same keyboard?

alternativly u could simply try another way to handle inputs:
implements KeyListener
public void keyPressed(KeyEvent ke)
{controls[ke.getKeyCode()&0xFF] = 1;}

public void keyReleased(KeyEvent ke)
{controls[ke.getKeyCode()&0xFF] = 0;}

public void keyTyped(KeyEvent ke){}

goes to :-

public void processKeyEvent(KeyEvent ke)
{controls[ke.getKeyCode()&0xFF] = (ke.getID()==KeyEvent.KEY_RELEASED)?0:1 ;}

that asumes, that u store the keystates in a int-array wich is capable to hold 256 values

int[] controls=new int[256];

btw the code snippets r from abuse Smiley

弾幕 ☆ @mahonnaiseblog
Offline luisoft

JGO Coder

Projects: 6
Exp: 10 years

Java games rock!

« Reply #2 - Posted 2003-03-05 16:44:25 »

Yes it is the same keyboard. Actually is the same machine. I  have dual boot (Linux and Windows).
Instead of having such big array I have just 2 boolean variables (goingRight and goingLeft).
In KeyPressed I verify what key the user is pressing and then a set the variable to true and in the KeyReleased event I set the variable to false.
In WIndows enviroment works ok, but in Linux sometimes occur a keyreleased event even tough I have not released the key!
I have seen the bug report (see the link in my first post) in the sun homepage but it is matter of the X/Windows enviroment of Unix like OS
But I have to overcome this problem...
Any suggestions?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zparticle

Senior Devvie

Thick As A Brick

« Reply #3 - Posted 2003-03-05 18:51:57 »

well this wouldn't be pretty but what about checking for a specified period of time after the keyReleased event before resetting the boolean.

So you get a key pressed set the boolean to true. When you get a keyReleased start the timer. If you get another keyPressed then kill the timer. In your rendering loop check to see if the timer has gone past a specified amount of time, this means you didn't get antoher keyPressed after the keyReleased so it must have been a real keyRelease event.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

theagentd (111 views)
2017-02-18 13:42:33

theagentd (115 views)
2017-02-18 13:35:16

h.pernpeintner (1279 views)
2017-01-24 22:39:11

h.pernpeintner (1267 views)
2017-01-24 22:38:32

Galdo (1827 views)
2017-01-12 13:44:09

Archive (1931 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2469 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2301 views)
2016-12-15 21:50:57

Lunch (2380 views)
2016-12-06 16:01:40

ral0r2 (2156 views)
2016-11-23 16:08:26
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!