The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.
Simple Directmedia Layer Forums
Trying to use scancode to get key input.
Joined: 31 Mar 2016
Posted: Thu Mar 31, 2016 5:59 pm
The wiki seems to be missing a ton of code samples, so I'm sorry if this seems like a stupid question. I'm trying to make a function that gets an integer to represent the scancode of a key then pass it to SDL from a Squirrel-scripted VM. I tried to use SDL_GetKeyFromScancode(), but it won't let me use an integer as input, so how to I turn an integer into an SDL_Scancode? I can't pass SDL_Scancode directly from Squirrel, or if i can, I don't know how.
Joined: 03 Jul 2014
Posted: Fri Apr 01, 2016 12:10 am
You can use SDL_GetKeyboardState to accomplish what you want to do.
Example code on how to use it:
bool KeyPressed(const int Key)
// Get a snapshot of the current state of the keyboard
const Uint8* pCurrentKeyState = SDL_GetKeyboardState(NULL);
* Make sure that 'Key' is a valid SDL_SCANCODE (don't wanna go out of bounds in the array)
* SDL_SCANCODE_A = 4
* SDL_NUM_SCANCODES = 512
if(Key >= SDL_SCANCODE_A && Key < SDL_NUM_SCANCODES)
int main(int argc, char* argv)
// Initialize SDL and such