Still trouble with choppy input

I’m still having problems where my input handler for keyboard input is firing for no keys pressed. Even If I am holding down a key. I think windows is firing repeating pressed/released events. This causes my sprite to stop during some frames and move during others. Here is my code.



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

private void updateInput()
    {      
//        if(state == PLAY)
//        {
            if(controls[KeyEvent.VK_UP] == 1)
            {
                diry = -2;
                dirx = 0;
                hero.setDirection(Hero.UP);            
                hero.start();
            }            
            else if(controls[KeyEvent.VK_DOWN] == 1)
            {
                diry = 2;
                dirx = 0;
                hero.setDirection(Hero.DOWN);
                hero.start();
               
            }
            else if(controls[KeyEvent.VK_LEFT] == 1)
            {
                dirx = -2;
                diry = 0;
                hero.setDirection(Hero.LEFT);
                hero.start();
    
            }
            else if(controls[KeyEvent.VK_RIGHT] == 1)
            {
                dirx = 2;
                diry = 0;
                hero.setDirection(Hero.RIGHT);
                hero.start();
                
            }
            else
            {
                dirx = 0;
                diry = 0;               
               // hero.stop();
            }
            
            if(controls[KeyEvent.VK_ESCAPE] == 1) running = false;
}



I call updateInput() every frame.

If I remove the block for the last else everything is smooth as glass. :-/

Pretty similar to what I’m doing for a bunch of things…

What does hero.start() do ?

Kev

Hero.start() sets the Hero’s animated flag to true, it doesn’t move the Hero or anything like that.

I assume you’ve already done this, but you could stick some debug in the processKeyEvent to see whats happening.

Kev

I just thought of something… How does unix handle a key being held down.
I’m actually running on windows running on a sunpci card on a solaris box.

I dunno about Solaris but I know for Linux you need to play with the key repeat (I think it was either enable or disable and it wasn’t obvious which one you wanted. In fact I think you wanted to Disable because otherwise X starts ignoring it as a “stuck key” but I could be mis-remebering.)

[quote]I dunno about Solaris but I know for Linux you need to play with the key repeat (I think it was either enable or disable and it wasn’t obvious which one you wanted. In fact I think you wanted to Disable because otherwise X starts ignoring it as a “stuck key” but I could be mis-remebering.)
[/quote]
disable via which api jeff?

Linux command line.

You may want to check out
http://developer.java.sun.com/developer/bugParade/bugs/4504217.html

and vote for it. (I think you’re looking for “xset r off”)

[quote]You may want to check out
http://developer.java.sun.com/developer/bugParade/bugs/4504217.html

and vote for it. (I think you’re looking for “xset r off”)
[/quote]
I voted for it. xset r off only appears to affect the current window on solaris though.