java - How can I check keyboard for a single press? -


i can't figure how condition work. there keyboard.iskeydown(//anykey) condition?

import org.lwjgl.input.keyboard; import org.lwjgl.input.mouse;  public class inputhandler {      public static boolean currentkeystate, previouskeystate;      public static void update() {         previouskeystate = currentkeystate;          if (//condition keydown) {             currentkeystate = true;          } else {             currentkeystate = false;         }     }      public static boolean keyreleased() {        if (currentkeystate == true && previouskeystate == false) {             return true;        } else {             return false;         }    } } 

here's c# version of i'm trying accomplish. there method similar keyboard.getstate() in java?

using system; using system.collections.generic; using system.linq; using microsoft.xna.framework; using microsoft.xna.framework.input;  namespace game.controls {     public class inputhandler     {     public keyboardstate currentkeystate;     public keyboardstate previouskeystate;      public inputhandler()     {         currentkeystate = new keyboardstate();         previouskeystate = new keyboardstate();     }      public void update()     {         previouskeystate = currentkeystate;         currentkeystate = keyboard.getstate();     }      public bool isheld(keys key)     {         if (currentkeystate.iskeydown(key))         {             return true;         }         else         {             return false;         }     }      public bool isreleased(keys key)     {         if (currentkeystate.iskeyup(key) && previouskeystate.iskeydown(key))         {             return true;         }         else         {             return false;         }     }      public bool ispressed(keys key)     {         if (currentkeystate.iskeydown(key) && previouskeystate.iskeyup(key))         {             return true;         }         else         {             return false;         }     } } 

}

if (keyboard.geteventkey() == keyboard.key_a) {     if (keyboard.geteventkeystate()) {         system.out.println("a key pressed");     }     else {         system.out.println("a key released");     } } 

you can refer this document

for getting input methods.

for keys supported refer http://www.lwjgl.org/javadoc/org/lwjgl/input/keyboard.html


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -