~ubuntu-branches/ubuntu/lucid/fceux/lucid

« back to all changes in this revision

Viewing changes to gfceux/get_key/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-12-14 08:05:17 UTC
  • Revision ID: james.westby@ubuntu.com-20091214080517-abi5tj8avthfan7c
Tags: upstream-2.1.2+repack
ImportĀ upstreamĀ versionĀ 2.1.2+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// main.cpp
 
2
// get_fceu_key
 
3
//   this program opens an SDL window and gets an input event from the user.
 
4
//   it than prints the values that are needed in the fceux config
 
5
//   this was written to be used with gfceux, the GTK frontend for gfceu
 
6
 
 
7
// Lukas Sabota
 
8
// Licensed under the GPL v2
 
9
// July 16, 2008
 
10
 
 
11
#include<iostream>
 
12
#include<SDL.h>
 
13
 
 
14
const int WIDTH = 300;  
 
15
const int HEIGHT = 300;
 
16
const int BPP = 4;
 
17
const int DEPTH = 32;
 
18
 
 
19
using namespace std;
 
20
 
 
21
int main(int argc, char* argv[])
 
22
{
 
23
    // the caption doesn't set on intrepid
 
24
    // TODO: test on ubuntu 8.04
 
25
    SDL_WM_SetCaption("Press any key. . .", 0);
 
26
        
 
27
          SDL_Surface *screen;
 
28
        SDL_Event event;
 
29
        
 
30
        // open any joysticks
 
31
        for(int i = 0; i < SDL_NumJoysticks(); i++)
 
32
                SDL_JoystickOpen(i);
 
33
 
 
34
    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_SWSURFACE)))
 
35
    {
 
36
        SDL_Quit();
 
37
        return 1;
 
38
    }
 
39
 
 
40
    while(1) 
 
41
    {
 
42
        while(SDL_PollEvent(&event)) 
 
43
        {      
 
44
            switch (event.type) 
 
45
            {
 
46
                case SDL_QUIT:
 
47
                    return 0;
 
48
                    // this code was modified from drivers/sdl/input.cpp in fceu so 
 
49
                    //   that the same values will be written in the config as fceux --inputcfg
 
50
                      case SDL_KEYDOWN:
 
51
                    cout << "BUTTC_KEYBOARD" << endl;
 
52
                    cout << 0 << endl;
 
53
                    cout << event.key.keysym.sym << endl;
 
54
                    return 1;
 
55
                case SDL_JOYBUTTONDOWN:
 
56
                    cout << "BUTTC_JOYSTICK" << endl;
 
57
                    cout << event.jbutton.which << endl;
 
58
                    cout << event.jbutton.button << endl; 
 
59
                    return 1;
 
60
                case SDL_JOYHATMOTION:
 
61
                    if(event.jhat.value != SDL_HAT_CENTERED)
 
62
                    {
 
63
                        cout << "BUTTC_JOYSTICK" << endl;
 
64
                        cout << event.jhat.which << endl;
 
65
                        cout <<  (0x2000 | ((event.jhat.hat & 0x1F) << 8) |
 
66
                                             event.jhat.value) << endl;
 
67
                        return 1;
 
68
                    }
 
69
                        break;
 
70
            }
 
71
        }
 
72
    }   
 
73
    return 0;
 
74
}
 
75