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)
This commit is contained in:
punkrockguy318 2008-07-16 05:58:39 +00:00
parent ee1e742261
commit 6785d6708a
2 changed files with 90 additions and 0 deletions

2
get_key/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
g++ `sdl-config --cflags --libs` main.cpp

88
get_key/main.cpp Normal file
View File

@ -0,0 +1,88 @@
#include<iostream>
#include<SDL.h>
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;
}