diff options
author | punkrockguy318 <punkrockguy318@users.sf.net> | 2011-10-19 00:49:42 +0400 |
---|---|---|
committer | punkrockguy318 <punkrockguy318@users.sf.net> | 2011-10-19 00:49:42 +0400 |
commit | 436392070ad8dbf652fb79305ca2c260deb3d041 (patch) | |
tree | bdff9fe69c8e2793b5d333de758e71e325c12e7f /getSDLKey | |
parent | 5f1037b219f1c4a8c25f328362a84f78f4aa811a (diff) |
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.
Diffstat (limited to 'getSDLKey')
-rw-r--r-- | getSDLKey/Makefile | 18 | ||||
-rw-r--r-- | getSDLKey/README | 27 | ||||
-rw-r--r-- | getSDLKey/getSDLKey.cpp | 78 |
3 files changed, 123 insertions, 0 deletions
diff --git a/getSDLKey/Makefile b/getSDLKey/Makefile new file mode 100644 index 00000000..88ca9d1a --- /dev/null +++ b/getSDLKey/Makefile @@ -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
diff --git a/getSDLKey/README b/getSDLKey/README new file mode 100644 index 00000000..359dd4e1 --- /dev/null +++ b/getSDLKey/README @@ -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? diff --git a/getSDLKey/getSDLKey.cpp b/getSDLKey/getSDLKey.cpp new file mode 100644 index 00000000..75341f11 --- /dev/null +++ b/getSDLKey/getSDLKey.cpp @@ -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; +} |