1 /**
2  * SDL mouse+keyboard test
3 
4  * Copyright (C) 2008  Sylvain Beucler
5 
6  * This file is part of GNU FreeDink
7 
8  * GNU FreeDink is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 3 of the
11  * License, or (at your option) any later version.
12 
13  * GNU FreeDink is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see
20  * <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "SDL.h"
24 
main(int argc,char * argv[])25 int main(int argc, char*argv[])
26 {
27   int enable_unicode = 1;
28   if (argc > 1)
29     {
30       if (strcmp(argv[1], "--no-unicode") == 0)
31 	{
32 	  enable_unicode = 0;
33 	}
34       else
35 	{
36 	  printf("Usage: %s [--no-unicode]\n", argv[0]);
37 	  return EXIT_SUCCESS;
38 	}
39     }
40 
41   SDL_Init(SDL_INIT_VIDEO);
42   SDL_Surface *screen = SDL_SetVideoMode(320, 200, 0, 0);
43   SDL_Flip(screen);
44   /* EnableUNICODE needs to be placed after SDL_Init, and it does not
45      matter whether it's placed before or after SetVideoMode) */
46   SDL_EnableUNICODE(enable_unicode);
47   SDL_WM_GrabInput(SDL_GRAB_ON);
48 
49   SDL_Event e;
50   while (SDL_WaitEvent(&e))
51     {
52       if (e.type == SDL_KEYDOWN)
53 	{
54 
55 	  printf("DOWN: code=%d(keyname'%s')\tu=%d(ascii'%c')\n",
56 		 e.key.keysym.sym,
57 		 SDL_GetKeyName(e.key.keysym.sym),
58 		 e.key.keysym.unicode,
59 		 e.key.keysym.unicode);
60 	  fflush(stdout);
61 	  if (e.key.keysym.sym == SDLK_ESCAPE)
62 	    break;
63 	}
64       if (e.type == SDL_KEYUP)
65 	{
66 	  /* No Unicode on KEYUP :/ */
67 	  printf("UP: code=%d(keyname'%s')\tu=%d(ascii'%c')\n",
68 		 e.key.keysym.sym,
69 		 SDL_GetKeyName(e.key.keysym.sym),
70 		 e.key.keysym.unicode,
71 		 e.key.keysym.unicode);
72 	  fflush(stdout);
73 	}
74       if (e.type == SDL_QUIT)
75 	break;
76     }
77 
78   SDL_Quit();
79   return EXIT_SUCCESS;
80 }
81