gpt4 book ai didi

c++ - SDL2/Qt C++ 未读取操纵杆输入但已识别

转载 作者:行者123 更新时间:2023-11-30 03:20:50 24 4
gpt4 key购买 nike

那是我的 main.cpp

#include "mainwindow.h"
#include <QApplication>
#include "SDL.h"

#include <QDebug>

#undef main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
SDL_Window *window = nullptr;
SDL_Surface *windowSurface = nullptr;

SDL_Init(SDL_INIT_VIDEO);
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,"1");
SDL_Init( SDL_INIT_JOYSTICK);

SDL_Joystick *joystick = SDL_JoystickOpen(0);

qDebug()<<SDL_JoystickName(joystick);
qDebug()<<(SDL_JoystickNumAxes(joystick));
qDebug()<<(SDL_JoystickNumButtons(joystick));
window = SDL_CreateWindow("SDL CodingMadeEasy Series", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN);
windowSurface = SDL_GetWindowSurface(window);

SDL_Event ev;
int x;
bool isRunning = true;

while(isRunning)
{
while(SDL_PollEvent(&ev) != 0)
{
if(ev.type == SDL_JOYBUTTONDOWN)
{
qDebug()<<"Button Clicked";
}
}
// Drawing the current image to the window
SDL_UpdateWindowSurface(window);
}
return a.exec();
}

它可以识别 PS4 Controller ,因为它会打印出 qDebug 行。我尝试更改 ev.type ==(其他与 JOYSTICK 无关的东西)并且它工作得很好,所以显然 JOYBUTTONDOWN 有问题。

有什么帮助吗?

最佳答案

已通过启用操纵杆事件修复

SDL_JoystickEventState(SDL_ENABLE);

关于c++ - SDL2/Qt C++ 未读取操纵杆输入但已识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52527832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com