title: GLFW with LWJGL - glfwGetKey once
body: <p>I'm developing a game with java and LWJGL3. But I don't understand how to fix my problem, I've tried to search on the internet but the information for LWJGL is minimal and I couldn't find anything for GLFW.</p>
  
  <p>Let's say for example I have a menu with 4 buttons (new game, options, credits, exit) and a count variable to know which one is selected. Every time the up arrow key is pressed I want to subtract one from the select, to select the previous one, and the same for the down arrow key, but I want to add one.</p>
  
  <p>The problem is the following: if in the frame 0 I press the arrow key the count variable is added but in the next frame the key is still pressed, so it is added again. I don't know how to fix this, I tried to changing GLFW_PRESS to GLFW_RELEASE, but I want the action to happen when the key was pressed.</p>
  
  <pre><code>if ((glfwGetKey(window, GLFW_KEY_UP) == GLFW_REPEAT) &amp;&amp; select &gt; 0) {
      button[select].toggleSelect();
      select--;
      button[select].toggleSelect();
  }
  
  if ((glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_REPEAT) &amp;&amp; select &lt; button.length) {
      button[select].toggleSelect();
      select++;
      button[select].toggleSelect();
  }
  </code></pre>
  
  <p>I know that this code can throw an array index out of bounds exception</p>