www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: redred on May 18, 2006, 01:26:43 am

Title: help!
Post by: redred on May 18, 2006, 01:26:43 am
What type of statement do you use to get a user input from what they typed? Please someone respond! Quick! Not much time left!
Title: help!
Post by: manumoi on May 18, 2006, 07:22:33 am
Hello,

In JPCT apps, you have the KeyMapper class to help you. Here is an example of how you can use it (taken from i don't remember which example of Egon)

Code: [Select]

   private void poll(){
KeyState state = null;
do{
   state = keyMapper.poll();  // call to the poll method of the KeyMapper instance
   if (state!=KeyState.NONE){
keyAffected(state); // call to a keyAffected method that will describe the action to do once a key is pushed
   }
}
while (state != KeyState.NONE);
    }


And an example of the keyAffected related method
Code: [Select]

  private void keyAffected(KeyState state){
int code = state.getKeyCode();
boolean event = state.getState();
System.out.println(code);
switch(code){
case (KeyEvent.VK_ESCAPE):
   escape = event;
   break;
case (KeyEvent.VK_LEFT):
   left = event;
   break;
case (KeyEvent.VK_RIGHT):
   right = event;
   break;
case (KeyEvent.VK_UP):
   forward = event;
   break;
case (KeyEvent.VK_DOWN):
   backward=event;
   break;
}



Manu
Title: Re: help!
Post by: EgonOlsen on May 18, 2006, 05:13:50 pm
Quote from: "redred"
Not much time left!
To do what exactly?
Title: help!
Post by: Uija on May 19, 2006, 09:14:19 am
The end is near! End everyone with a cool 3d app will be catched up by some aliens! :P
Title: help!
Post by: redred on May 20, 2006, 03:34:01 am
i kind of wanted a quick reply...hehe?
Title: help!
Post by: redred on May 20, 2006, 03:38:33 am
Quote from: "Uija"
The end is near! End everyone with a cool 3d app will be catched up by some aliens! :P
strange people in the world, strange...lol
Title: help!
Post by: redred on May 20, 2006, 03:42:17 am
Just incase this my post was read wrong, what i meant was
say i feel like making a calculator... this is where i want the user input to be used

number=([/i]somewaytogetwhatthepersontypedonthekeyboard)

If that changes things