sdl getch

Started by
2 comments, last by Mizipzor 18 years, 3 months ago
Im doing a test program for my A*, I use to use getch() for stepping through programs... but since this program uses SDL I dont want to shift between the console window and the sdl window, I made this function to wait for the user to press "s" (s for step that is [smile] hehe). But it doesnt work, when I reach this loop the program stands still and nothing happens. And, yes, Ive tried to press "s", lol.

	Uint8 *keystate;	// check the keyboard

	while(1) {	// wait for input to break
		keystate = SDL_GetKeyState(NULL);
		if(keystate[SDLK_s])
			return;
	}

Seemed to be to simple to fail. :S What am I doing wrong?
Advertisement
You're probably going to want to use an event polling system. Here's a nice article on that.
Rob Loach [Website] [Projects] [Contact]
Try calling SDL_PumpEvents() right before calling SDL_GetKeyState().
Problem solved, instead of checking the keyboard I just check for a keypress.

	SDL_Event event;	while(1) {	// wait for input to break		SDL_PollEvent(&event);		if(event.type == SDL_KEYDOWN)			return;	}

This topic is closed to new replies.

Advertisement