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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 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