GLFW 3.0.2 A multi-platform library for OpenGL, window and input

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Modules | Typedefs | Functions
Input handling

## Modules
| Joysticks
| Keyboard keys
| Modifier key flags
| Mouse buttons

## Typedefs
typedef void(* | GLFWmousebuttonfun )(GLFWwindow *, int, int, int)
| The function signature for mouse button callbacks. More...
typedef void(* | GLFWcursorposfun )(GLFWwindow *, double, double)
| The function signature for cursor position callbacks. More...
typedef void(* | GLFWcursorenterfun )(GLFWwindow *, int)
| The function signature for cursor enter/leave callbacks. More...
typedef void(* | GLFWscrollfun )(GLFWwindow *, double, double)
| The function signature for scroll callbacks. More...
typedef void(* | GLFWkeyfun )(GLFWwindow *, int, int, int, int)
| The function signature for keyboard key callbacks. More...
typedef void(* | GLFWcharfun )(GLFWwindow *, unsigned int)
| The function signature for Unicode character callbacks. More...

## Functions
int | glfwGetInputMode (GLFWwindow *window, int mode)
| Returns the value of an input option for the specified window. More...
void | glfwSetInputMode (GLFWwindow *window, int mode, int value)
| Sets an input option for the specified window. More...
int | glfwGetKey (GLFWwindow *window, int key)
| Returns the last reported state of a keyboard key for the specified window. More...
int | glfwGetMouseButton (GLFWwindow *window, int button)
| Returns the last reported state of a mouse button for the specified window. More...
void | glfwGetCursorPos (GLFWwindow *window, double *xpos, double *ypos)
| Retrieves the last reported cursor position, relative to the client area of the window. More...
void | glfwSetCursorPos (GLFWwindow *window, double xpos, double ypos)
| Sets the position of the cursor, relative to the client area of the window. More...
GLFWkeyfun | glfwSetKeyCallback (GLFWwindow *window, GLFWkeyfun cbfun)
| Sets the key callback. More...
GLFWcharfun | glfwSetCharCallback (GLFWwindow *window, GLFWcharfun cbfun)
| Sets the Unicode character callback. More...
GLFWmousebuttonfun | glfwSetMouseButtonCallback (GLFWwindow *window, GLFWmousebuttonfun cbfun)
| Sets the mouse button callback. More...
GLFWcursorposfun | glfwSetCursorPosCallback (GLFWwindow *window, GLFWcursorposfun cbfun)
| Sets the cursor position callback. More...
GLFWcursorenterfun | glfwSetCursorEnterCallback (GLFWwindow *window, GLFWcursorenterfun cbfun)
| Sets the cursor enter/exit callback. More...
GLFWscrollfun | glfwSetScrollCallback (GLFWwindow *window, GLFWscrollfun cbfun)
| Sets the scroll callback. More...
int | glfwJoystickPresent (int joy)
| Returns whether the specified joystick is present. More...
const float * | glfwGetJoystickAxes (int joy, int *count)
| Returns the values of all axes of the specified joystick. More...
const unsigned char * | glfwGetJoystickButtons (int joy, int *count)
| Returns the state of all buttons of the specified joystick. More...
const char * | glfwGetJoystickName (int joy)
| Returns the name of the specified joystick. More...

## Key and button actions
#define | GLFW_RELEASE 0
| The key or button was released. More...
#define | GLFW_PRESS 1
| The key or button was pressed. More...
#define | GLFW_REPEAT 2
| The key was held down until it repeated. More...

## Detailed Description

## Macro Definition Documentation

#define GLFW_PRESS 1

#define GLFW_RELEASE 0

#define GLFW_REPEAT 2

## Typedef Documentation

typedef void(* GLFWcharfun)(GLFWwindow *, unsigned int)

This is the function signature for Unicode character callback functions.

Parameters

  [in] | window | The window that received the event.
  [in] | character | The Unicode code point of the character.

See Also
  glfwSetCharCallback

typedef void(* GLFWcursorenterfun)(GLFWwindow *, int)

This is the function signature for cursor enter/leave callback functions.

Parameters

  [in] | window | The window that received the event.
  [in] | entered | `GL_TRUE` if the cursor entered the window's client area, or `GL_FALSE` if it left it.

See Also
  glfwSetCursorEnterCallback

typedef void(* GLFWcursorposfun)(GLFWwindow *, double, double)

This is the function signature for cursor position callback functions.

Parameters

  [in] | window | The window that received the event.
  [in] | xpos | The new x-coordinate of the cursor.
  [in] | ypos | The new y-coordinate of the cursor.

See Also
  glfwSetCursorPosCallback

typedef void(* GLFWkeyfun)(GLFWwindow *, int, int, int, int)

This is the function signature for keyboard key callback functions.

Parameters

  [in] | window | The window that received the event.
  [in] | key | The keyboard key that was pressed or released.
  [in] | scancode | The system-specific scancode of the key.
  [in] | action | GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT.
  [in] | mods | Bit field describing which modifier keys were held down.

See Also
  glfwSetKeyCallback

typedef void(* GLFWmousebuttonfun)(GLFWwindow *, int, int, int)

This is the function signature for mouse button callback functions.

Parameters

  [in] | window | The window that received the event.
  [in] | button | The mouse button that was pressed or released.
  [in] | action | One of `GLFW_PRESS` or `GLFW_RELEASE`.
  [in] | mods | Bit field describing which modifier keys were held down.

See Also
  glfwSetMouseButtonCallback

typedef void(* GLFWscrollfun)(GLFWwindow *, double, double)

This is the function signature for scroll callback functions.

Parameters

  [in] | window | The window that received the event.
  [in] | xoffset | The scroll offset along the x-axis.
  [in] | yoffset | The scroll offset along the y-axis.

See Also
  glfwSetScrollCallback

## Function Documentation

void glfwGetCursorPos | ( | GLFWwindow * | window,
|  | double * | xpos,
|  | double * | ypos
| ) |  |

This function returns the last reported position of the cursor to the specified window.

If the cursor is disabled (with `GLFW_CURSOR_DISABLED`) then the cursor position is unbounded and limited only by the minimum and maximum values of a `double`.

The coordinate can be converted to their integer equivalents with the `floor` function. Casting directly to an integer type works for positive coordinates, but fails for negative ones.

Parameters

  [in] | window | The desired window.
  [out] | xpos | Where to store the cursor x-coordinate, relative to the left edge of the client area, or `NULL`.
  [out] | ypos | Where to store the cursor y-coordinate, relative to the to top edge of the client area, or `NULL`.

See Also
  glfwSetCursorPos

int glfwGetInputMode | ( | GLFWwindow * | window,
|  | int | mode
| ) |  |

Parameters

  [in] | window | The window to query.
  [in] | mode | One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or `GLFW_STICKY_MOUSE_BUTTONS`.

See Also
  glfwSetInputMode

const float* glfwGetJoystickAxes | ( | int | joy,
|  | int * | count
| ) |  |

This function returns the values of all axes of the specified joystick.

Parameters

  [in] | joy | The joystick to query.
  [out] | count | Where to store the size of the returned array. This is set to zero if an error occurred.

Returns
  An array of axis values, or `NULL` if the joystick is not present.

Note
  The returned array is allocated and freed by GLFW. You should not free it yourself.
  The returned array is valid only until the next call to glfwGetJoystickAxes for that joystick.

const unsigned char* glfwGetJoystickButtons | ( | int | joy,
|  | int * | count
| ) |  |

This function returns the state of all buttons of the specified joystick.

Parameters

  [in] | joy | The joystick to query.
  [out] | count | Where to store the size of the returned array. This is set to zero if an error occurred.

Returns
  An array of button states, or `NULL` if the joystick is not present.

Note
  The returned array is allocated and freed by GLFW. You should not free it yourself.
  The returned array is valid only until the next call to glfwGetJoystickButtons for that joystick.

const char* glfwGetJoystickName | ( | int | joy | ) |

This function returns the name, encoded as UTF-8, of the specified joystick.

Parameters

  [in] | joy | The joystick to query.

Returns
  The UTF-8 encoded name of the joystick, or `NULL` if the joystick is not present.

Note
  The returned string is allocated and freed by GLFW. You should not free it yourself.
  The returned string is valid only until the next call to glfwGetJoystickName for that joystick.

int glfwGetKey | ( | GLFWwindow * | window,
|  | int | key
| ) |  |

This function returns the last state reported for the specified key to the specified window. The returned state is one of `GLFW_PRESS` or `GLFW_RELEASE`. The higher-level state `GLFW_REPEAT` is only reported to the key callback.

If the `GLFW_STICKY_KEYS` input mode is enabled, this function returns `GLFW_PRESS` the first time you call this function after a key has been pressed, even if the key has already been released.

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

Parameters

  [in] | window | The desired window.
  [in] | key | The desired keyboard key.

Returns
  One of `GLFW_PRESS` or `GLFW_RELEASE`.

Note
  `GLFW_KEY_UNKNOWN` is not a valid key for this function.

int glfwGetMouseButton | ( | GLFWwindow * | window,
|  | int | button
| ) |  |

This function returns the last state reported for the specified mouse button to the specified window.

If the `GLFW_STICKY_MOUSE_BUTTONS` input mode is enabled, this function returns `GLFW_PRESS` the first time you call this function after a mouse button has been pressed, even if the mouse button has already been released.

Parameters

  [in] | window | The desired window.
  [in] | button | The desired mouse button.

Returns
  One of `GLFW_PRESS` or `GLFW_RELEASE`.

int glfwJoystickPresent | ( | int | joy | ) |

This function returns whether the specified joystick is present.

Parameters

  [in] | joy | The joystick to query.

Returns
  `GL_TRUE` if the joystick is present, or `GL_FALSE` otherwise.

GLFWcharfun glfwSetCharCallback | ( | GLFWwindow * | window,
|  | GLFWcharfun | cbfun
| ) |  |

This function sets the character callback of the specific window, which is called when a Unicode character is input.

The character callback is intended for text input. If you want to know whether a specific key was pressed or released, use the key callback instead.

Parameters

  [in] | window | The window whose callback to set.
  [in] | cbfun | The new callback, or `NULL` to remove the currently set callback.

Returns
  The previously set callback, or `NULL` if no callback was set or an error occurred.

GLFWcursorenterfun glfwSetCursorEnterCallback | ( | GLFWwindow * | window,
|  | GLFWcursorenterfun | cbfun
| ) |  |

This function sets the cursor boundary crossing callback of the specified window, which is called when the cursor enters or leaves the client area of the window.

Parameters

  [in] | window | The window whose callback to set.
  [in] | cbfun | The new callback, or `NULL` to remove the currently set callback.

Returns
  The previously set callback, or `NULL` if no callback was set or an error occurred.

void glfwSetCursorPos | ( | GLFWwindow * | window,
|  | double | xpos,
|  | double | ypos
| ) |  |

This function sets the position of the cursor. The specified window must be focused. If the window does not have focus when this function is called, it fails silently.

If the cursor is disabled (with `GLFW_CURSOR_DISABLED`) then the cursor position is unbounded and limited only by the minimum and maximum values of a `double`.

Parameters

  [in] | window | The desired window.
  [in] | xpos | The desired x-coordinate, relative to the left edge of the client area, or `NULL`.
  [in] | ypos | The desired y-coordinate, relative to the top edge of the client area, or `NULL`.

See Also
  glfwGetCursorPos

GLFWcursorposfun glfwSetCursorPosCallback | ( | GLFWwindow * | window,
|  | GLFWcursorposfun | cbfun
| ) |  |

This function sets the cursor position callback of the specified window, which is called when the cursor is moved. The callback is provided with the position relative to the upper-left corner of the client area of the window.

Parameters

  [in] | window | The window whose callback to set.
  [in] | cbfun | The new callback, or `NULL` to remove the currently set callback.

Returns
  The previously set callback, or `NULL` if no callback was set or an error occurred.

void glfwSetInputMode | ( | GLFWwindow * | window,
|  | int | mode,
|  | int | value
| ) |  |

Parameters

  [in] | window | The window whose input mode to set.
  [in] | mode | One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or `GLFW_STICKY_MOUSE_BUTTONS`.
  [in] | value | The new value of the specified input mode.

If `mode` is `GLFW_CURSOR`, the value must be one of the supported input modes:

- `GLFW_CURSOR_NORMAL` makes the cursor visible and behaving normally.
- `GLFW_CURSOR_HIDDEN` makes the cursor invisible when it is over the client area of the window.
- `GLFW_CURSOR_DISABLED` disables the cursor and removes any limitations on cursor movement.

If `mode` is `GLFW_STICKY_KEYS`, the value must be either `GL_TRUE` to enable sticky keys, or `GL_FALSE` to disable it. If sticky keys are enabled, a key press will ensure that glfwGetKey returns GLFW_PRESS the next time it is called even if the key had been released before the call. This is useful when you are only interested in whether keys have been pressed but not when or in which order.

If `mode` is `GLFW_STICKY_MOUSE_BUTTONS`, the value must be either `GL_TRUE` to enable sticky mouse buttons, or `GL_FALSE` to disable it. If sticky mouse buttons are enabled, a mouse button press will ensure that glfwGetMouseButton returns GLFW_PRESS the next time it is called even if the mouse button had been released before the call. This is useful when you are only interested in whether mouse buttons have been pressed but not when or in which order.

See Also
  glfwGetInputMode

GLFWkeyfun glfwSetKeyCallback | ( | GLFWwindow * | window,
|  | GLFWkeyfun | cbfun
| ) |  |

This function sets the key callback of the specific 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 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 window has lost focus, i.e. `GLFW_FOCUSED` will be false and the focus callback will have already 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 retrieved with glfwGetKey.

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

Parameters

  [in] | window | The window whose callback to set.
  [in] | cbfun | The new key callback, or `NULL` to remove the currently set callback.

Returns
  The previously set callback, or `NULL` if no callback was set or an error occurred.

GLFWmousebuttonfun glfwSetMouseButtonCallback | ( | GLFWwindow * | window,
|  | GLFWmousebuttonfun | cbfun
| ) |  |

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

When a window loses focus, it will generate synthetic mouse button release events for all pressed mouse buttons. You can tell these events from user-generated events by the fact that the synthetic ones are generated after the window has lost focus, i.e. `GLFW_FOCUSED` will be false and the focus callback will have already been called.

Parameters

  [in] | window | The window whose callback to set.
  [in] | cbfun | The new callback, or `NULL` to remove the currently set callback.

Returns
  The previously set callback, or `NULL` if no callback was set or an error occurred.

GLFWscrollfun glfwSetScrollCallback | ( | GLFWwindow * | window,
|  | GLFWscrollfun | cbfun
| ) |  |

This function sets the scroll callback of the specified window, which is called when a scrolling device is used, such as a mouse wheel or scrolling area of a touchpad.

The scroll callback receives all scrolling input, like that from a mouse wheel or a touchpad scrolling area.

Parameters

  [in] | window | The window whose callback to set.
  [in] | cbfun | The new scroll callback, or `NULL` to remove the currently set callback.

Returns
  The previously set callback, or `NULL` if no callback was set or an error occurred.