keyTyped not working?

Hi there!
So I working on the movement in my RPG.
Now it is so:
The Hero goes AND runs 16 Pixel(keyPressed).
But now I want that the Hero GOES 32 Pixel. And run 16 Pixel.

So I thought Im using keyTyped, when the Player push LEFT he move 32 Pixel.If he hold it pressed he mobe 16.
BUT it dont work :frowning:

Did I do something wrong in keyTyped?

[code=java]
public void keyTyped(int key, char c)
{
if(schalter.MovementAllowed){

        switch(key)
        {
            case Input.KEY_UP:
                    if(used==false){
		TypedUP=true; 
                    used=true;
                    lastDirection=3;
                    movement=true;
                 }
                 break;
      }

}
}



At my Movement Code
[code=java]
 if(TypedRIGHT && schalter.player_x<Kollision.getWidth()-40
          && blocked[schalter.player_x+48][schalter.player_y+48] == false
          && blocked[schalter.player_x+48][schalter.player_y+61] == false
          && schalter.player_x +32 != npcKollision_X[0]
          && schalter.MovementAllowed)
      {
         p.x=p.x-32;
         schalter.player_x=schalter.player_x+32;
      }

EDIT: Ok I think I know how to make it without. Im using this…Or not -.-"

keyTyped only runs when you press AND release the key. Unless you really want that behaviour, I suggest you override the keyPressed method instead.

EDIT: Wait a second, I guess you aren’t using a keylistener since the keyTyped method doesn’t have a single KeyEvent argument. Where did you get that code from?

Umm…how are you getting input?
What defines “keyTyped(int key, char c)”? What is “Input”?

Im using Slick. In

public void init(GameContainer gc)throws SlickException
{

I do


if (gc instanceof AppGameContainer) {
			app = (AppGameContainer) gc;
		}

      
         i = gc.getInput();   //INPUT
          


Ok so keyTyped would not work how I wanted.

Is there another method so that if the player press ONES he moves 32 Pixel? Else 16.

Oh I’ve never used Slick so I can’t help much ;D

One way you can handle this problem is using the delta time (provided in the update method) to calculate how long a key is pressed.

so something like

if (input.isKeyDown(Input.KEY_LEFT)) {
leftButtonDownTime += delta;
}

Then depending on how long its held down you move 16px or 32px.

Hope that helps.

Check out if your program received your press first (by put in System.out.println). If yes, something wrong with your move method.

EDIT: Ok I tested it some time and it doesnt is really negative so I let it this way. Thanks Kappa.

Yeah good idea!!
It work with just one beautyerror.

So if I press once he move 32px.
BUT if I hold pressed he moves ONE time 32px and after that 16px.
Yes I know why, because of my If(). But I dont know how to change it.
But I think I could live with it. First xD
I made it this way:


public void update(GameContainer gc, int delta) throws SlickException
    {

     START = System.currentTimeMillis();

     checkBewegung();
     checkMessageBox();
     checkMapTeleport();
     checkMechanik(gc);
     checkNPC(); //NPCs und Truhen prüfen

     delta=10;


     if (i.isKeyDown(Input.KEY_LEFT)) 
       leftButtonDownTime += delta;
     

  
     AUSFUEHR = System.currentTimeMillis()-START;

     if(60 > (int)AUSFUEHR)
             gc.sleep(60-(int)AUSFUEHR);


    }


Movement Method:


 else if(LEFT && schalter.player_x>0
             && blocked[schalter.player_x][schalter.player_y+48] ==false
             && blocked[schalter.player_x][schalter.player_y+61] ==false
             && schalter.BewegungErlaubt )
     {

            if(leftButtonDownTime<10){
              p.x=p.x+32;
             schalter.player_x=schalter.player_x-32;
            }

        else {
           p.x=p.x+16;
          schalter.player_x=schalter.player_x-16;
         }

      }



In the keyPressed I just did


case Input.KEY_LEFT:
                      LEFT=false;
                      TypedLEFT=false;
                      benutzt=false;
                      bewegung=false;
                      leftButtonDownTime=0;
                      break;