#include
#include "sdl.h"
// # prgma comment (lib, "sdl.lib")
// Screen Width # Define Width 480 // Screen Height # Define Height 320
#define safe_release (p) {if (p! = null) {SDL_FREESURFACE (P); (P) = null;}}
SDL_SURFACE * GSCREEN
Void onkeyup (SDL_KEYBOARDEVENT * KEY);
Void PrintModifiers (SDLMOD MOD);
INT Main (int Argc, char * argv []) {// initialize SDL's subsystems if (SDL_INIT (SDL_INIT_VIDEO) <0) {fprintf (stderr, "unable to init SDL:% S / N", SDL_GETERROR ()); exit (1); }
INT DONE = 0; SDL_EVENT Event; SDL_ENABLEUNICODE (1);
Atexit (SDL_QUIT); GSCreen = SDL_SETVIDEOMODE (Width, Height, 32, SDL_swsurface); // init (); // if we fail, return error. if (gscreen == null) {fprintf (stderr, "unable to set up VIDEO:% S / N ", SDL_GETERROR ()); exit (1);} // main loop: {while (SDL_Pollevent (& Event)) {switch (event.type) {Case SDL_KeyDown : {If (Event.key.keysym.sym == SDLK_ESCAPE) DONE = true;} Break; Case SDL_KEYUP: {onkeyup (& Event.key);} Break;}}} Safe_release (gscreen); SDL_Quit (); Return 0 }
Void onkeyup (SDL_KEYBOARDEVENT * key) {/ * is it a release or a press? * / if (key-> type == SDL_KEYUP) Printf ("Release: -"); Else Printf ("press: -"); / * Print The hardware scancode first * / printf ("scancode: 0x% 02x", key-> keysym.scancode; / * print the name of the key * / printf (", name:% s", SDL_GetKeyName (Key- > Keysym.SYM); / * We want to print the Unicode Info, But we need to make * / / * Sure ITS a press * / / * don't have unicode info * / @@ '' '店(Key-> Type == SDL_KEYDOWN) {/ * if the unicode value is less Than 0x80 THE * / / * Unicode Value Can Be Used to get a printable * / / / * representation of the key, using (char) Unicode. * / Printf (", Unicode:"); if (key-> keysym. commicode <0x80 && key-> keysym.unicode> 0) {Printf ("% C (0x% 04x)", (char) key-> KeySym.Unicode, key-> keysym.Unicode);} else {printf ("? (0x% 04x)", key-> keysym.Unicode);}}} }printf ("/ n"); / * Print Modifier Info * / PRIN TMODIFIERS (Key-> Keysym.mod);