SDL_GetKeyState

Name

SDL_GetKeyState -- Get a snapshot of the current keyboard state

Synopsis

#include "SDL.h"

Uint8 *SDL_GetKeyState(int *numkeys);

Description

Gets a snapshot of the current keyboard state. The current state is returned as a pointer to an array. The size of this array is stored in numkeys. The array is indexed by the SDLK_* symbols (see SDLKey). A value of 1 means that the key is pressed and a value of 0 means that it is not. The pointer returned is a pointer to an internal SDL array. It will be valid for the whole lifetime of the application and should not be freed by the caller.

Note: Use SDL_PumpEvents to update the state array.

Note: This function gives you the current state after all events have been processed, so if a key or button has been pressed and released before you process events, then the pressed state will never show up in the getstate calls.

Note: This function doesn't take into account whether shift has been pressed or not.

Example

Uint8 *keystate = SDL_GetKeyState(NULL);
if ( keystate[SDLK_RETURN] ) printf("Return Key Pressed.\n");
if ( keystate[SDLK_RIGHT] && keystate[SDLK_UP] ) printf("Right and Up Keys Pressed.\n");

See Also

SDLKey, SDL_PumpEvents

SDL_GetKeyState (last edited 2008-12-02 14:06:32 by SalokineTerata)