-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
47 lines (38 loc) · 1.32 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <SDL.h>
#include <iostream>
SDL_Joystick *joy;
// Initialize the joystick subsystem
int main() {
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
// Check for joystick
if (SDL_NumJoysticks() > 0) {
// Open joystick
joy = SDL_JoystickOpen(0);
// Print joystick info
if (joy) {
std::cout << "Opened Joystick 0" << std::endl;
std::cout << "Name: " << SDL_JoystickNameForIndex(0) << std::endl;
std::cout << "Number of Axes: " << SDL_JoystickNumAxes(joy) << std::endl;
std::cout << "Number of Buttons: " << SDL_JoystickNumButtons(joy) << std::endl;
std::cout << "Number of Balls: " << SDL_JoystickNumBalls(joy) << std::endl;
} else {
std::cout << "Couldn't open Joystick 0" << std::endl;
}
SDL_Event e;
//Print all events
while(true)
{
while( SDL_PollEvent( &e ) != 0 )
{
std::cout << "Someone pressed a button!" << std::endl;
std::cout << e.type << std::endl;
}
}
// Close if opened
if (SDL_JoystickGetAttached(joy)) {
SDL_JoystickClose(joy);
}
} else {
std::cout << "Controller not connected, please connect a controller." << std::endl;
}
}