From b9c4ec67264be87dbbad461026463ba64bc41bad Mon Sep 17 00:00:00 2001 From: mcmartin Date: Fri, 28 Apr 2006 05:02:37 +0000 Subject: [PATCH] Complete keyjamming application git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2336 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/keys/Makefile | 2 +- tools/keys/keyjam.c | 82 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/tools/keys/Makefile b/tools/keys/Makefile index 6dbea7f4c..894a9919e 100644 --- a/tools/keys/Makefile +++ b/tools/keys/Makefile @@ -1,5 +1,5 @@ all: keyjam.c - gcc `sdl-config --cflags` `sdl-config --libs` -o keyjam keyjam.c + gcc $(shell sdl-config --cflags) -o keyjam keyjam.c $(shell sdl-config --libs) -lSDL_gfx clean: rm -f keyjam diff --git a/tools/keys/keyjam.c b/tools/keys/keyjam.c index 7526db76c..869b21f29 100644 --- a/tools/keys/keyjam.c +++ b/tools/keys/keyjam.c @@ -1,13 +1,63 @@ #include #include #include "SDL.h" +#include "SDL_gfxPrimitives.h" + +#define BUFFERSIZE 1024 static int keystate[SDLK_LAST]; +static char held_keys[BUFFERSIZE]; + + +void +DrawCenteredText (SDL_Surface *s, int y, const char *c) +{ + int w = strlen (c) * 8; + + stringRGBA(s, (s->w - w) / 2, y, c, 0xc0, 0xc0, 0xc0, 0xff); +} + +void +DrawScreen (SDL_Surface *s) +{ + int y; + SDL_FillRect (s, NULL, SDL_MapRGB (s->format, 0, 0, 0x80)); + DrawCenteredText (s, 8, "Key Jamming"); + + y = 32; + + DrawCenteredText (s, y, "Many keyboards have hardware that does not permit them to send"); + y += 8; + DrawCenteredText (s, y, "arbitrary keychords to the computer. This can complicate games"); + y += 8; + DrawCenteredText (s, y, "with keyboard control, as activating certain controls may lock out"); + y += 8; + DrawCenteredText (s, y, "others. This application lets you pre-test control combinations so"); + y += 8; + DrawCenteredText (s, y, "as to avoid such conflicts."); + + y += 16; + DrawCenteredText (s, y, "Test your keyboard by pressing key combinations. The keyboard's"); + y += 8; + DrawCenteredText (s, y, "status will be reported in the bottom half of the screen. When"); + y += 8; + DrawCenteredText (s, y, "configuring keys for a game, do not select keys that do not all"); + y += 8; + DrawCenteredText (s, y, "register when simultaneously pressed."); + + y += 16; + DrawCenteredText (s, y, "Press ESCAPE to exit."); + + DrawCenteredText (s, 300, held_keys); + + SDL_Flip (s); +} int main (int argc, char *argv[]) { SDL_Event event; + SDL_Surface *screen; int quit = 0; int i, changed; @@ -19,18 +69,22 @@ main (int argc, char *argv[]) } /* Set a video mode */ - if (!SDL_SetVideoMode (320, 200, 0, 0)) + if (!(screen = SDL_SetVideoMode (640, 480, 0, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT))) { fprintf (stderr, "Could not set video mode: %s\n", SDL_GetError()); SDL_Quit (); exit (-1); } + SDL_WM_SetCaption ("Key Jammer", "Key Jammer"); + for (i = 0; i < SDLK_LAST; i++) { keystate[i] = 0; } + DrawScreen (screen); + /* Loop until an SDL_QUIT event is found */ while( !quit ) { changed = 0; @@ -56,15 +110,35 @@ main (int argc, char *argv[]) } } if (changed) { - printf ("Status:"); + held_keys[0] = '\0'; for (i = 0; i < SDLK_LAST; i++) { if (keystate[i]) { - printf(" %s", SDL_GetKeyName (i)); + if (held_keys[0]) + { + strcat(held_keys, " "); + } + strcat(held_keys, SDL_GetKeyName (i)); + } + if (strlen (held_keys) > 200) + { + break; } } - printf ("\n"); + for (i = 0; i < BUFFERSIZE; i++) + { + if (!held_keys[i]) + { + break; + } + held_keys[i] = toupper (held_keys[i]); + } + DrawScreen (screen); + } + if (keystate[SDLK_ESCAPE]) + { + quit = 1; } }