Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glfwSetKeyCallback Documentation Appears to be Incorrect #2534

Open
gudenau opened this issue Apr 10, 2024 · 1 comment
Open

glfwSetKeyCallback Documentation Appears to be Incorrect #2534

gudenau opened this issue Apr 10, 2024 · 1 comment
Labels
input Keyboard, joystick or mouse

Comments

@gudenau
Copy link

gudenau commented Apr 10, 2024

The documentation for glfwSetKeyCallback says that synthetic key events for pressed keys are fired when windows loose focus. In my experience this doesn't happen, the documentation should be updated to reflect this.

@dougbinks dougbinks added the input Keyboard, joystick or mouse label Apr 10, 2024
@dougbinks
Copy link
Contributor

The documentation is correct, so any deviation from this behaviour is either a code issue or the window has not lost input focus.

The code for _glfwInputWindowFocus in windows.c, a platform independent part of GLFW, explicitly sets all keys which have GLFW_PRESS state to GLFW_RELEASE through the _glfwInputKey function which calls the callback.

See:

glfw/src/window.c

Lines 43 to 70 in 228e582

void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused)
{
assert(window != NULL);
assert(focused == GLFW_TRUE || focused == GLFW_FALSE);
if (window->callbacks.focus)
window->callbacks.focus((GLFWwindow*) window, focused);
if (!focused)
{
int key, button;
for (key = 0; key <= GLFW_KEY_LAST; key++)
{
if (window->keys[key] == GLFW_PRESS)
{
const int scancode = _glfw.platform.getKeyScancode(key);
_glfwInputKey(window, key, scancode, GLFW_RELEASE, 0);
}
}
for (button = 0; button <= GLFW_MOUSE_BUTTON_LAST; button++)
{
if (window->mouseButtons[button] == GLFW_PRESS)
_glfwInputMouseClick(window, button, GLFW_RELEASE, 0);
}
}
}

The events.c test is a good way to check this as it outputs both window focus and key events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
input Keyboard, joystick or mouse
Projects
None yet
Development

No branches or pull requests

2 participants