opengl - GLFW Keyboard Input Registers As Multiple Clicks -


in current lwjgl application using glfw window input handler have set class handle called keyboard.java extends glfwkeycallback. have correctly set keyboard input class when click on key if not click if fast enough (very quickly) registers multiple clicks. have presented documentation below:

keyboard class

public class keyboard extends glfwkeycallback {      //variables     public static boolean keys[] = new boolean[65536];      @override     public void invoke(long window, int key, int scancode, int action, int mods) {          keys[key] = action == glfw_press;      }  } 

implementation

public static void handleinput() {     if (keyboard.keys[glfw_key_space]) {         system.out.println("space");         glfwpollevents();     } } 

the above method implemented in main game loop , called once frame.

result

initialised lwjgl version: 3.1.2 build 29

space

space

space

space

the above: "space" should outputted every time click space when click relatively fast, above result of many "spaces".

conclusion: possible click of space registered once no matter how long hold it. thanks

in handleinput() function, testing see if keyboard.keys[glfw_key_space] true, , if is, execute statement. problem test becomes false when stop hitting space, take seconds happen.

my suggestion: once tested keyboard.keys[glfw_key_space], make false.

public static void handleinput() {     if (keyboard.keys[glfw_key_space]) {         keyboard.keys[glfw_key_space] = false;         system.out.println("space");         glfwpollevents();     } } 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -