检测ESC键的按下抬起,抬起后退出窗口。
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int SDL_main(int argc, char * argv[])
{
SDL_Window *window = NULL;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)
{
fprintf(stderr, "SDL_Init() failed\n");
exit(-1);
}
atexit(SDL_Quit);
window = SDL_CreateWindow("Window Title",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,480, SDL_WINDOW_OPENGL);
if(NULL==window){
fprintf(stderr, "SDL_CreateWindow() failed\n");
exit(-1);
}
SDL_ShowWindow(window);
SDL_Event event;
Uint32 exit = 0;
while( !exit )
{
SDL_WaitEvent(&event);
switch( event.type )
{
case SDL_KEYUP:
if( event.key.keysym.sym == SDLK_ESCAPE)
{
exit = 1;
}
break;
default:
break;
}
}
SDL_DestroyWindow(window);
window = NULL;
return 0;
}
1439

被折叠的 条评论
为什么被折叠?



