Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <SDL.h>
- SDL_Surface *surface;
- SDL_Window *window;
- SDL_Joystick *joystick;
- int main(int argc, char *argv[]) {
- if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0) {
- fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
- return 1;
- }
- printf("%i joystick(s) found.\n", SDL_NumJoysticks());
- printf("The names of the joysticks are:\n");
- int i;
- for (i = 0; i < SDL_NumJoysticks(); i++) {
- joystick = SDL_JoystickOpen(i);
- printf("%s\n", SDL_JoystickName(joystick));
- }
- printf("Video Driver: %s\n", SDL_GetCurrentVideoDriver());
- window = SDL_CreateWindow(
- "An SDL2 window", // window title
- SDL_WINDOWPOS_UNDEFINED, // initial x position
- SDL_WINDOWPOS_UNDEFINED, // initial y position
- 640, // width, in pixels
- 480, // height, in pixels
- SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS);
- if(window==NULL) {
- // In the event that the window could not be made...
- fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
- return 1;
- }
- SDL_JoystickEventState(SDL_ENABLE);
- SDL_Event event;
- int running = 1;
- while (running) {
- while(SDL_PollEvent(&event)) {
- switch(event.type) {
- case SDL_KEYUP:
- case SDL_KEYDOWN:
- case SDL_JOYAXISMOTION:
- case SDL_JOYHATMOTION:
- case SDL_JOYBUTTONUP:
- case SDL_JOYBUTTONDOWN:
- printf("Input Detected\n");
- printf("Event State: %d\n", event.jbutton.state);
- break;
- case SDL_QUIT:
- running = 0;
- break;
- default:
- break;
- }
- switch (event.key.keysym.sym) {
- case SDLK_ESCAPE:
- running = 0;
- break;
- default:
- break;
- }
- }
- }
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement