I have a basic camera and movement system in my game, and would like to press escape to halt all movement/camera motion, and allow the user control of their mouse cursor.
When pressing escape however, it takes multiple inputs (from the time that the button is actually down), and registers all of them.
My code switches a boolean looking when escape is pressed, and I suspect the problem is that looking is switched multiple times per escape press.
Code:
bool looking = true;
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
looking = !looking;
std::cout << looking << std::endl;
}
// ...
}
The cout call gives the following output after one press:
0
1
0
1
0
1
0
The expected output is a single boolean output when escape is pressed (initially this would be 0, and would alternate with successive presses).
Is there a better function call than glfwGetKey() for specifically detecting a single button press?