i want to connect joystick to my c++ qt program in windows.I studied about programming with win32 api using the joystickapi library in microsoft guid for joystick program But I didn't understand exactly What should I do after checking the system compatibility?
Completion description:
my code for system compatibility:
JOYINFO joyinfo;
UINT wNumDevs, wDeviceID;
BOOL bDev1Attached, bDev2Attached;
void joyCapablitis(){
if((wNumDevs = joyGetNumDevs()) == 0)
qDebug()<<"no driver available";
bDev1Attached = joyGetPos(JOYSTICKID1,&joyinfo) != JOYERR_UNPLUGGED;
bDev2Attached = wNumDevs == 2 && joyGetPos(JOYSTICKID2,&joyinfo) !=
JOYERR_UNPLUGGED;
if(bDev1Attached || bDev2Attached) // decide which joystick to use
{
wDeviceID = bDev1Attached ? JOYSTICKID1 : JOYSTICKID2;
}
else
qDebug()<<"no device available";
}
I want to track the movement of buttons and simulate it in software.How can I get joystick information (such as number of button and button on or off) from win32 api?
I wrote a QJoystick lib in a form of a Qt module but it's not yet released.
Here is a bit of code for Windows.
First, you need to initialize DirectInput:
Second, setup callbacks:
EnumJoysticksCallback
is where you create a virtual device for your joystick:And
EnumObjectsCallback
will be executed for every button or axis during the enumeration process: