From 6785d6708ab36dc3373a69a5417436c3c070e6b3 Mon Sep 17 00:00:00 2001 From: punkrockguy318 Date: Wed, 16 Jul 2008 05:58:39 +0000 Subject: [PATCH] Wrote the get key program. This program creates an SDL window and waits for user input. It then will print the button type, device number, and button number. Some of the code was derived straight from the fceu codebase to ensure full compatibility. I want gfceux to be able to directly modify the button configuration. With fceux new config file system, gfceux will be able to rewrite values based on user input. This would be a much friendlier option than the whole "titlebar" input sytem. I wrote this in C, because I didn't want another bullshit dependency to get gfceux to run right (pygame sdl bindings) --- get_key/build.sh | 2 ++ get_key/main.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100755 get_key/build.sh create mode 100644 get_key/main.cpp diff --git a/get_key/build.sh b/get_key/build.sh new file mode 100755 index 00000000..2c4f69db --- /dev/null +++ b/get_key/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +g++ `sdl-config --cflags --libs` main.cpp diff --git a/get_key/main.cpp b/get_key/main.cpp new file mode 100644 index 00000000..05e6386d --- /dev/null +++ b/get_key/main.cpp @@ -0,0 +1,88 @@ +#include +#include + +const int WIDTH = 640; +const int HEIGHT = 480; +const int BPP = 4; +const int DEPTH = 32; + + +using namespace std; + +int main(int argc, char* argv[]) +{ + SDL_WM_SetCaption("Press any key. . .", NULL); + SDL_Surface *screen; + SDL_Event event; + + // open any joysticks + for(int i = 0; i < SDL_NumJoysticks(); i++) + SDL_JoystickOpen(i); + + if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE))) + { + SDL_Quit(); + return 1; + } + + while(1) + { + while(SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + return 0; + case SDL_KEYDOWN: + cout << "BUTTC_KEYBOARD" << endl; + cout << 0 << endl; + cout << event.key.keysym.sym << endl; + return 1; + case SDL_JOYBUTTONDOWN: + cout << "BUTTC_JOYSTICK" << endl; + cout << event.jbutton.which << endl; + cout << event.jbutton.button << endl; + return 1; + case SDL_JOYHATMOTION: + if(event.jhat.value != SDL_HAT_CENTERED) { + cout << "BUTTC_JOYSTICK" << endl; + cout << event.jhat.which << endl; + cout << (0x2000 | ((event.jhat.hat & 0x1F) << 8) | + event.jhat.value) << endl; + return 1; + } + break; +/* case SDL_JOYAXISMOTION: + if(LastAx[event.jaxis.which][event.jaxis.axis] == 0x100000) { + if(abs(event.jaxis.value) < 1000) { + LastAx[event.jaxis.which][event.jaxis.axis] = event.jaxis.value; + } + } else { + if(abs(LastAx[event.jaxis.which][event.jaxis.axis] - event.jaxis.value) >= 8192) { + bc->ButtType[wb] = BUTTC_JOYSTICK; + bc->DeviceNum[wb] = event.jaxis.which; + bc->ButtonNum[wb] = (0x8000 | event.jaxis.axis | + ((event.jaxis.value < 0) + ? 0x4000 : 0)); + return(1); + } + } + break; + case SDL_KEYDOWN: + keypress = 1; + cout << (int)event.key.keysym.sym; + break; + case SDL_JOYAXISMOTION: + if ( (event.jaxis.value < -3200 ) | | (event.jaxis.value > 3200) ) + { + if (event.jaxis == 0) + { +*/ + + + } + } + } + return 0; +} +