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:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
all: keyjam.c
|
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:
|
clean:
|
||||||
rm -f keyjam
|
rm -f keyjam
|
||||||
|
|||||||
+78
-4
@@ -1,13 +1,63 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
#include "SDL_gfxPrimitives.h"
|
||||||
|
|
||||||
|
#define BUFFERSIZE 1024
|
||||||
|
|
||||||
static int keystate[SDLK_LAST];
|
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
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
SDL_Surface *screen;
|
||||||
int quit = 0;
|
int quit = 0;
|
||||||
int i, changed;
|
int i, changed;
|
||||||
|
|
||||||
@@ -19,18 +69,22 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set a video mode */
|
/* 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());
|
fprintf (stderr, "Could not set video mode: %s\n", SDL_GetError());
|
||||||
SDL_Quit ();
|
SDL_Quit ();
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_WM_SetCaption ("Key Jammer", "Key Jammer");
|
||||||
|
|
||||||
for (i = 0; i < SDLK_LAST; i++)
|
for (i = 0; i < SDLK_LAST; i++)
|
||||||
{
|
{
|
||||||
keystate[i] = 0;
|
keystate[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DrawScreen (screen);
|
||||||
|
|
||||||
/* Loop until an SDL_QUIT event is found */
|
/* Loop until an SDL_QUIT event is found */
|
||||||
while( !quit ) {
|
while( !quit ) {
|
||||||
changed = 0;
|
changed = 0;
|
||||||
@@ -56,15 +110,35 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changed) {
|
if (changed) {
|
||||||
printf ("Status:");
|
held_keys[0] = '\0';
|
||||||
for (i = 0; i < SDLK_LAST; i++)
|
for (i = 0; i < SDLK_LAST; i++)
|
||||||
{
|
{
|
||||||
if (keystate[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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user