Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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 1058 times)
0 Members and 1 Guest are viewing this topic.
Offline luisoft

JGO Coder


Projects: 6


Java games rock!


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

Hi.
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:

http://developer.java.sun.com/developer/bugParade/bugs/4338703.html

Does anyone knows how to overcome this problem?

Thanks,
Luiz Fernando
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


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

erm...

"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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
implements KeyListener
...
addKeyListener(this);
...
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 :-

1  
2  
3  
4  
enableEvents(AWTEvent.KEY_EVENT_MASK);
...
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


Java games rock!


« Reply #2 - Posted 2003-03-05 17: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 Member




Thick As A Brick


« Reply #3 - Posted 2003-03-05 19: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.

 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!