You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
VideoClient98/src/directinputjoystick.h

48 lines
1.3 KiB
C

#ifndef DIRECTINPUTJOYSTICK_H
#define DIRECTINPUTJOYSTICK_H
#include <QObject>
#include <windows.h>
#include <dinput.h>
#include <QThread>
class DirectInputJoystick : public QObject
{
Q_OBJECT
public:
explicit DirectInputJoystick(QObject *parent = nullptr);
~DirectInputJoystick();
bool initialize();
void startListening();
signals:
// 轴变化信号axis: 0-X, 1-Y, 2-Z; value: -1.0 ~ 1.0
void axisChanged(int axis, double value);
// 按钮状态变化button: 按钮编号从0开始pressed: 是否按下)
void buttonChanged(int button, bool pressed);
// 方向按钮状态变化direction: 按钮编号上下左右pressed: 是否按下)
void directionChanged(int direction);
// 错误信号
void errorOccurred(const QString &message);
private:
bool setupDevice();
void cleanup();
static BOOL CALLBACK enumAxesCallback(const DIDEVICEOBJECTINSTANCE* doi, VOID* context);
static BOOL CALLBACK enumJoysticksCallback(const DIDEVICEINSTANCE* instance, VOID* context);
DIJOYSTATE lastState;
LPDIRECTINPUT8 m_pDirectInput = nullptr;
LPDIRECTINPUTDEVICE8 m_pJoystick = nullptr;
HANDLE m_hEvent = nullptr;
QThread *m_workerThread;
bool m_isRunning = false;
};
#endif // DIRECTINPUTJOYSTICK_H