sdl: added getSDLKey utility to determine the SDL keysym of particular keys on your keyboard. useful for editing fceux.cfg to remap hotkeys until gui is implemented. see README for more details.

This commit is contained in:
punkrockguy318 2011-10-18 20:49:42 +00:00
parent 5f1037b219
commit 436392070a
3 changed files with 123 additions and 0 deletions

18
getSDLKey/Makefile Normal file
View File

@ -0,0 +1,18 @@
PREFIX = /usr
OUTFILE = getSDLKey
CC = gcc
OBJS = getSDLKey.o
LIBS = -lSDL
all: ${OBJS}
${CC} -o ${OUTFILE} ${LIBS} ${OBJS}
clean:
rm -f ${OUTFILE} ${OBJS}
install:
install -m 755 -D getSDLKey ${PREFIX}/bin/getSDLKey
getSDLKey.o = getSDLKey.cpp

27
getSDLKey/README Normal file
View File

@ -0,0 +1,27 @@
#############################################
# getSDLKey - Lukas Sabota - October, 2011 #
#############################################
1. Dependencies:
gcc
make
libsdl
2. Installing
Run "make" to compile to "getSDLKey". Run "make install" as root if you would like to install "getSDLKey" into a user-specified PREFIX.
3. Running
Type "./getSDLKey" while in this directory to run.
4. About this tool.
This is a tool to determine what the SDL keysym for a particular key on your keyboard is. This is especially useful when mapping hotkeys to FCEUX. Take a look at an excerpt of ~/.fceux/fceux.cfg:
SDL.Hotkeys.SaveState = 286
Apparently, F5 on my system is SDL keysym 286. If you wanted to remap this to a different key, run ./getSDLKey and press the desired key to see what keysym you should modify your configuration with.
5. Bugs
You can report any issues with this tool in the FCEUX SourceForge bugtracker. Alternatively, you can contact me directly at LTsmooth42 _at_ gmail _dot_ com.
6. Future
I plan to implement a GUI for remapping these keys so you don't have to do this in the future, but we're all very busy people, aren't we?

78
getSDLKey/getSDLKey.cpp Normal file
View File

@ -0,0 +1,78 @@
#include<SDL/SDL.h>
void DisplayState(SDL_KeyboardEvent *key)
{
if (key->type == SDL_KEYUP)
printf("RELEASED: ");
else
printf("PRESSED: ");
}
void DisplayModifiers(SDL_KeyboardEvent *key)
{
SDLMod modifier = key->keysym.mod;
if( modifier & KMOD_NUM ) printf( "NUMLOCK " );
if( modifier & KMOD_CAPS ) printf( "CAPSLOCK " );
if( modifier & KMOD_MODE ) printf( "MODE " );
if( modifier & KMOD_LCTRL ) printf( "LCTRL " );
if( modifier & KMOD_RCTRL ) printf( "RCTRL " );
if( modifier & KMOD_LSHIFT ) printf( "LSHIFT " );
if( modifier & KMOD_RSHIFT ) printf( "RSHIFT " );
if( modifier & KMOD_LALT ) printf( "LALT " );
if( modifier & KMOD_RALT ) printf( "RALT " );
if( modifier & KMOD_LMETA ) printf( "LMETA " );
if( modifier & KMOD_RMETA ) printf( "RMETA " );
}
void DisplayKey(SDL_KeyboardEvent *key)
{
printf( "%s\n", SDL_GetKeyName(key->keysym.sym));
}
void DisplayKeysym(SDL_KeyboardEvent *key)
{
printf ("%d\n", key->keysym.sym);
}
int main(int argc, char** argv)
{
SDL_Surface *screen;
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(320, 240, 0, SDL_ANYFORMAT);
if (screen == NULL)
{
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
SDL_Event event;
int running = 1;
while(running) {
while(SDL_PollEvent(&event)) {
switch(event.type){
case SDL_KEYDOWN:
case SDL_KEYUP:
DisplayState(&event.key);
DisplayModifiers(&event.key);
DisplayKey(&event.key);
DisplayKeysym(&event.key);
break;
case SDL_QUIT:
running = 0;
break;
}
}
}
return 0;
}