glfwSetKeyCallback

Sets the key callback.

This function sets the key callback of the specified window, which is called when a key is pressed, repeated or released.

The key functions deal with physical keys, with layout independent key tokens named after their values in the standard US keyboard layout. If you want to input text, use the character callback instead.

When a window loses input focus, it will generate synthetic key release events for all pressed keys. You can tell these events from user-generated events by the fact that the synthetic ones are generated after the focus loss event has been processed, i.e. after the window focus callback has been called.

The scancode of a key is specific to that platform or sometimes even to that machine. Scancodes are intended to allow users to bind keys that don't have a GLFW key token. Such keys have key set to GLFW_KEY_UNKNOWN, their state is not saved and so it cannot be queried with @ref glfwGetKey.

Sometimes GLFW needs to generate synthetic key events, in which case the scancode may be zero.

extern (C) @nogc nothrow __gshared
glfwSetKeyCallback

Parameters

window GLFWwindow*

The window whose callback to set.

callback GLFWkeyfun

The new key callback, or null to remove the currently set callback.

Return Value

The previously set callback, or null if no callback was set or the library had not been initialized.

@callback_signature

void function_name(GLFWwindow* window, int key, int scancode, int action, int mods)

For more information about the callback parameters, see the function pointer type.

Errors: Possible errors include @ref GLFW_NOT_INITIALIZED.

Thread Safety

This function must only be called from the main thread.

@sa @ref input_key

Meta

Since

Added in version 1.0. @glfw3 Added window handle parameter and return value.

Ingroup: input