#include #include int main() { // Inicializar SDL if (!SDL_Init(SDL_INIT_GAMEPAD)) { std::cerr << "Error inicializando SDL: " << SDL_GetError() << std::endl; return 1; } std::cout << "Prueba de triggers L2/R2 como botones digitales" << std::endl; std::cout << "Conecta un mando arcade y presiona L2 o R2" << std::endl; std::cout << "Presiona ESC para salir" << std::endl; // Abrir primer gamepad disponible SDL_Gamepad* gamepad = nullptr; SDL_JoystickID* joysticks = SDL_GetJoysticks(nullptr); if (joysticks) { for (int i = 0; joysticks[i]; i++) { if (SDL_IsGamepad(joysticks[i])) { gamepad = SDL_OpenGamepad(joysticks[i]); if (gamepad) { std::cout << "Gamepad conectado: " << SDL_GetGamepadName(gamepad) << std::endl; break; } } } SDL_free(joysticks); } if (!gamepad) { std::cout << "No se encontró ningún gamepad compatible" << std::endl; SDL_Quit(); return 1; } bool running = true; SDL_Event event; while (running) { while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_EVENT_QUIT: running = false; break; case SDL_EVENT_GAMEPAD_AXIS_MOTION: if (event.gaxis.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER) { if (event.gaxis.value > 16384) { std::cout << "L2 PRESIONADO como botón digital (valor: " << event.gaxis.value << ")" << std::endl; } } else if (event.gaxis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) { if (event.gaxis.value > 16384) { std::cout << "R2 PRESIONADO como botón digital (valor: " << event.gaxis.value << ")" << std::endl; } } break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: std::cout << "Botón presionado: " << event.gbutton.button << std::endl; break; } } // Verificar ESC para salir const bool* keyboard_state = SDL_GetKeyboardState(nullptr); if (keyboard_state[SDL_SCANCODE_ESCAPE]) { running = false; } SDL_Delay(16); // ~60 FPS } if (gamepad) { SDL_CloseGamepad(gamepad); } SDL_Quit(); return 0; }