Wiki Page Content

Keyboard Support

Include File(s): SDL_keyboard.h, SDL_keycode.h, SDL_scancode.h

Introduction

This category contains functions for handling keyboard inputs.

SDL uses two different types of values to represent keys on the keyboard - scancode and keycode.

SDL_Scancode values are used to represent the physical location of a keyboard key on the keyboard. Values of this type are used to represent keyboard keys in the key.keysym.scancode field of the SDL_Event structure, among other places. The values in the SDL_Scancode enumeration are based on the USB usage page standard (http://www.usb.org/developers/docs/). Scancode constants use the symbol name prefixed with SDL_SCANCODE_ (eg: SDL_SCANCODE_SPACE).

SDL_Keycode values are mapped to the current layout of the keyboard and correlate to an SDL_Scancode. Values of this type are used to represent key symbols in the key.keysym.sym field of the SDL_Event structure, among other places. The values in the SDL_Keycode enumeration are based on Unicode values representing the unmodified character that would be generated by pressing the key, or the scancode value with the high bit set (bitwise ORed with 0x40000000) for those keys that do not generate characters. Keycode constants use the symbol name (lowercased for letters) prefixed with SDLK_ (eg: SDLK_SPACE).

The main difference between these two values comes into play in situations where the operating system is mapping the physical keyboard keys to different virtual letters. For instance, when a standard QWERTY keyboard is mapped to a German QWERTZ layout, the "Y" key will generate events with a scancode of SDL_SCANCODE_Y, but a keycode of SDLK_z. Which one to use is left to the application: scancodes are suited in situations where controls are layout-dependent (eg. the "WASD" keys as left-handed arrow keys), whereas keycodes are better suited to situations where controls are character-dependent (eg. the "I" key for Inventory).

Enumerations

Structures

Functions


CategoryCategory

None: CategoryKeyboard (last edited 2014-07-28 18:15:41 by PhilippWiesemann)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit