Complete keyjamming application

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2336 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
mcmartin
2006-04-28 05:02:37 +00:00
parent 1f37aa6007
commit b9c4ec6726
2 changed files with 79 additions and 5 deletions
+78 -4
View File
@@ -1,13 +1,63 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}
}