Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 weirdness  (Read 3771 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Posted 2008-01-05 20:37:06 »

Howdy

Immediately after calling Display.update(), I use
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
while( Keyboard.next() )
{
   int key = Keyboard.getEventKey();
   boolean down = Keyboard.getEventKeyState();
   boolean repeat = Keyboard.isRepeatEvent();

   for( int j = 0; j < keyListeners.size(); j++ )
   {
      if( down )
         keyListeners.get( j ).keyDown( key, repeat );
      else
         keyListeners.get( j ).keyUp( key );
   }
}


to process pending key events. The problem is that there are occasional erroneous events. When holding down "W", for example, i get something like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
Down W at 2.517
   Up W at 5.621
Down W at 5.621
   Up W at 6.358
Down W at 6.358
   Up W at 9.075
Down W at 9.075
   Up W at 11.39
Down W at 11.39
   Up W at 20.246
Down W at 20.246
   Up W at 33.866
Down W at 33.866
   Up W at 35.208
Down W at 35.208
   Up W at 35.275


The KeyboardTest does not exhibit this behaviour, so PEBKAC applies, but I haven't the foggiest what I could be doing to cause this behaviour.

I did find a similar case on the LWJGL forums, but he was doing multithreaded stuff, which I am not.
This is running on Linux, by the way

Has anyone seen anything similar?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2008-01-05 21:12:19 »

Wild guess: wireless keyboard......?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #2 - Posted 2008-01-05 21:40:39 »

Good thought, but I'm on a laptop.

Also, LWJGL's keyboard test works perfectly, so I'm fairly sure it's something I'm doing.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #3 - Posted 2008-01-06 00:01:29 »

Curiouser and curiouser, it might be the case that this is someone else's problem.

I've pared it down to this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
public class KeyboardTest
{
   private static boolean weirdKeyboardRepeatPlease = true;

   public static void main( String[] args )
   {
      Display.setVSyncEnabled( weirdKeyboardRepeatPlease )

      try
      {
         Display.create();

         while( !Display.isCloseRequested() )
         {
            Display.update();
            while( Keyboard.next() )
            {
               System.out.println( "Checking key:" + Keyboard.getKeyName( Keyboard.getEventKey() ) );
               System.out.println( "Pressed:" + Keyboard.getEventKeyState() );
            }
         }
      }
      catch( Exception e )
      {
         e.printStackTrace();
      }
   }
}


When the flag is true, this will consistently display the odd key repeat behaviour within about ten seconds of holding a key down. When the flag is false, it behaves as expected.

Can anyone repeat this oddity, or am I loosing it?

edit: Just tested, and it doesn't matter if vsync is enabled before or after Display.create(). When vsync is enabled, I get the odd key repeat behaviour. Time to test in Windows methinks...

edit2: Everything works fine on windows.

edit3: It happens in both fullscreen and windowed modes
Offline Niwak

Senior Member


Medals: 1
Projects: 1



« Reply #4 - Posted 2008-01-07 07:14:39 »

You get the exact same problem with the AWT event queue under Linux ; you have to filter the key repeat behavior.
You can see how it is done in jinput (AWTKeyboard class) or looking into Kevin Glass tutorial on the subject.

   Vincent
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #5 - Posted 2008-01-07 11:17:09 »

No, this behaviour is different. The AWT key repeat happens frequently and regularly, like a good key repeat should.

The behaviour I am seeing is infrequent and very irregular (see the timestamps in the first post - those values are in seconds). In addition KeyBoard.areRepeatEventsEnabled() return false and Keyboard.isRepeatEvent() also returns false for the erroneous key events. On top of that, it only happens when vsync mode is on.

In summary, I wish it was just the AWT key repeat.
Offline elias

Senior Member





« Reply #6 - Posted 2008-01-07 18:25:15 »

Thanks a lot for the accurate bug report. I managed to reproduce it with your test example, and I've comitted a fix to subversion. The problem is that X11 won't tell us by default whether a key event is repeated so lwjgl uses a heuristic to detect them instead. The heuristic apparently fails once in a while depending on timing. The fix was to try and use an extension function to enable detection of repeated key events.

 - elias

Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #7 - Posted 2008-01-07 18:34:40 »

Cheesy Great stuff
Offline gouessej
« Reply #8 - Posted 2008-04-12 11:02:28 »

Cheesy Great stuff
Why don't you do like me?

if(System.getProperty("os.name").compareToIgnoreCase("Linux")==0)
            try{Runtime.getRuntime().exec("xset -r off");
                System.out.println("xset -r off");
               }
        catch(final IOException ioe)
        {ioe.printStackTrace();}

and in a shutdown hook :

if(System.getProperty("os.name").compareToIgnoreCase("Linux")==0)
            {try{Runtime.getRuntime().exec("xset -r on");
                 System.out.println("xset -r on");
                }
             catch(IOException ioe)
             {ioe.printStackTrace();}
            }

It might be improved but it works fine in TUER.

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.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (34 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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

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

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!