How do I detect ONLY 1 mouse press with GLFW?

In JavaScript, you got mousedown and mouseup. I’m sure you all know this, but mousedown is true while you have the (left) mouse button pressed, and mouseup is true once you let go of the (left) mouse button and only once.

How can I detect mouseup with GLFW? I’ve noticed GLFW_PRESS is like mousedown, but GLFW_RELEASE is what I’m looking for but if I’m polling the current mouse state:


int mouseState = glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT);

…in an infinite loop, I can’t just do:


	else if (mouseState == GLFW_RELEASE) {

		m_mouseUp = true;
	}


… m_mouseUp, will always be true (except when I press the left button). I’m either not thinking this right, or I’m not finding the correct API call.

By registering a mouse button callback with glfwSetMouseButtonCallback(). The callback will be invoked whenever a button press or release event occurs for the given window.

If you’re polling, you need to keep track of the prior state. E.g.


static int oldState = GL_RELEASE;
int newState = glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT);
if (newState == GL_RELEASE && oldState == GL_PRESS) {
   // whatever
}
oldState = newState;

Note that glfwGetMouseButton() returns the state from the most recent mouse button event, so the value won’t change between calls to glfwPollEvents() (or glfwWaitEvents(), etc).

[QUOTE=GClements;1284074]By registering a mouse button callback with glfwSetMouseButtonCallback(). The callback will be invoked whenever a button press or release event occurs for the given window.

If you’re polling, you need to keep track of the prior state. E.g.


static int oldState = GL_RELEASE;
int newState = glfwGetMouseButton(win, GLFW_MOUSE_BUTTON_LEFT);
if (newState == GL_RELEASE && oldState == GL_PRESS) {
   // whatever
}
oldState = newState;

Note that glfwGetMouseButton() returns the state from the most recent mouse button event, so the value won’t change between calls to glfwPollEvents() (or glfwWaitEvents(), etc).[/QUOTE]

Perfect! That definitely did the trick, very simple solution too. Thanks!