Wiki Page Content

Differences between revisions 6 and 7
Revision 6 as of 2011-02-07 18:33:27
Size: 1762
Editor: KenBull
Comment: Renamed SDL_scancode
Revision 7 as of 2013-06-18 21:13:07
Size: 1774
Comment: Updated return types to match SDL_keyboard.h.
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
Uint8* SDL_GetKeyboardState(int* numkeys) const Uint8* SDL_GetKeyboardState(int* numkeys)
Line 24: Line 24:
Uint8 *state = SDL_GetKeyboardState(NULL); const Uint8 *state = SDL_GetKeyboardState(NULL);

DRAFT

SDL_GetKeyboardState

Use this function to get a snapshot of the current state of the keyboard.

Syntax

const Uint8* SDL_GetKeyboardState(int* numkeys)

Function Parameters

numkeys

if non-NULL, receives the length of the returned array

Return Value

Returns a pointer to an array of key states. *A value of 1 means that the key is pressed and a value of 0 means that it is not.* Indexes into this array are obtained by using SDL_Scancode values. *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.*

Code Examples

green

const Uint8 *state = SDL_GetKeyboardState(NULL);
if ( state[SDL_SCANCODE_RETURN] ) {
    printf("<RETURN> is pressed.\n");
}

Remarks

*green


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 green

calls.

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


CategoryAPI, CategoryKeyboard

None: SDL_GetKeyboardState (last edited 2013-12-07 14:28:51 by PhilippWiesemann)

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