Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL key input

Started by Boops Mar 3, 2004 at 7:28 AM 2 replies 950+ views
Original Post
Boops
Boops
Hello, I can read what keys are pressed with "Uint8 *keystate = SDL_GetKeyState(NULL);" and then checking keystate, and I can check wether or not a key is pressed with "if(event.type == SDL_KEYDOWN) key_is_pressed=true;" But if I use them in combination, I get memory related crashes! I want to make something that waits until a key is pressed, and then immediatly knows what key has been pressed. So first I get an SDL event and check if it is SDL_KEYDOWN, and after that has happened, another function gets SDL_GetKeyState and checks which one it was with a switch. This seems to give random crashes with a windows error about memory could not be read. Is this a known problem? Is there a proper way to do what I want? [edited by - BoopS on March 3, 2004 8:46:48 AM]
honny
honny

no bug of sdl about this .

i think its something in your code.

"I want to make something that waits until a key is pressed, and then immediatly knows what key has been pressed. "

for the first part u can do this ( are some simple function i often use ):


void aspetta ()
{
printf("inside : aspetta\n");

int done = 0;
SDL_Event event;

while ( done>=0 )
{
SDL_Delay (0100);

while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_KEYDOWN ) {done = -1;};
};//close internal while

};//close while checking done

}//close function


u can change this void function in a function returning a key pressed or a char :


if(event.type==SDL_KEYDOWN)
{
return (char)event.key.keysym.unicode;//for example return the char associated to the key
}


Seriko87
Seriko87
you might want to look up info on the getch() it waits until a key is pressed and then knows what key is pressed. All that is required is stdlib.h if i remember right.
AIM/YIM: Seriko87

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.