test/checkkeys.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
equal deleted inserted replaced
7638:783d1cff9b20 7639:9406b7dd2f2d
   115 }
   115 }
   116 
   116 
   117 static void
   117 static void
   118 PrintText(char *text)
   118 PrintText(char *text)
   119 {
   119 {
   120     unsigned char *spot, expanded[1024];
   120     char *spot, expanded[1024];
   121 
   121 
   122     expanded[0] = '\0';
   122     expanded[0] = '\0';
   123     for ( spot = text; *spot; ++spot )
   123     for ( spot = text; *spot; ++spot )
   124     {
   124     {
   125         size_t length = SDL_strlen(expanded);
   125         size_t length = SDL_strlen(expanded);
   126         SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", *spot);
   126         SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
   127     }
   127     }
   128     SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
   128     SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
   129 }
   129 }
   130 
   130 
   131 int
   131 int
   132 main(int argc, char *argv[])
   132 main(int argc, char *argv[])
   133 {
   133 {
   134     SDL_Window *window;
   134     SDL_Window *window;
   135     SDL_Event event;
   135     SDL_Event event;
   136     int done;
   136     int done;
       
   137 	
       
   138 	/* Enable standard application logging */
       
   139 	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   137 
   140 
   138     /* Initialize SDL */
   141     /* Initialize SDL */
   139     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   142     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   140         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   143 		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
   141         return (1);
   144         return (1);
   142     }
   145     }
   143 
   146 
   144     /* Set 640x480 video mode */
   147     /* Set 640x480 video mode */
   145     window = SDL_CreateWindow("CheckKeys Test",
   148     window = SDL_CreateWindow("CheckKeys Test",
   146                               SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
   149                               SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
   147                               640, 480, 0);
   150                               640, 480, 0);
   148     if (!window) {
   151     if (!window) {
   149         fprintf(stderr, "Couldn't create 640x480 window: %s\n",
   152         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
   150                 SDL_GetError());
   153                 SDL_GetError());
   151         quit(2);
   154         quit(2);
   152     }
   155     }
   153 
   156 
   154 #if __IPHONEOS__
   157 #if __IPHONEOS__
   164         /* Check for events */
   167         /* Check for events */
   165         SDL_WaitEvent(&event);
   168         SDL_WaitEvent(&event);
   166         switch (event.type) {
   169         switch (event.type) {
   167         case SDL_KEYDOWN:
   170         case SDL_KEYDOWN:
   168         case SDL_KEYUP:
   171         case SDL_KEYUP:
   169             PrintKey(&event.key.keysym, event.key.state, event.key.repeat);
   172 			PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
   170             break;
   173             break;
   171         case SDL_TEXTINPUT:
   174         case SDL_TEXTINPUT:
   172             PrintText(event.text.text);
   175             PrintText(event.text.text);
   173             break;
   176             break;
   174         case SDL_MOUSEBUTTONDOWN:
   177         case SDL_MOUSEBUTTONDOWN: