Any *simple* joystick reading sample program
Since no one replied to my last post...
Has anyone just a simple program to read one joystick''s X and Y-axis. No juggling with dialogue boxes or direct draw, just DirectInput.
Any help is appreciated since this is driving me nuts!
Microsoft has some basic directX tutorials on the MSDN network. The link is below. You''ll have to navigate through the Java based treeview they''ve put together to find the tutorials buried deep within. The location of the directinput tutorials is PlatformSDK->Graphics and Multimedia Services->DirectX->DirectInput->DirectInput Tutorials. There''s a lot of reference and peripheral information available too, not only on DirectInput, but all the DirectX Interfaces. Nice thing about the tutorials is that they focus only on that device. Check it out, it may be just what you''re looking for.
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/directx/dxstart_1x2d.htm
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/directx/dxstart_1x2d.htm
Problem is: I have followed all steps in the tutorial from the dx7-SDK, but is isn''t working. I''ll repost the code (more is added since the last post), so you can see that I''ve followed each step.
The only thing I can think of is that it doesn''t accept you to use the keyboard and the joystick at the same time.
BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance,void *pContext){ DIPROPRANGE diprg;//vars DIPROPDWORD dipdw;//vars if (dinput->CreateDeviceEx(pdidInstance->guidInstance,IID_IDirectInputDevice7,(void **)&dijoy[numofjoy],NULL)!=DI_OK) return(DIENUM_STOP); if (dijoy[numofjoy]->SetDataFormat(&c_dfDIJoystick)!=DI_OK) return(DIENUM_STOP); if (dijoy[numofjoy]->SetCooperativeLevel(windowhandle,DISCL_EXCLUSIVE/DISCL_FOREGROUND)!=DI_OK) return(DIENUM_STOP); diprg.diph.dwSize = sizeof(diprg); diprg.diph.dwHeaderSize = sizeof(diprg.diph); diprg.diph.dwObj = DIJOFS_X; diprg.diph.dwHow = DIPH_BYOFFSET; diprg.lMin = -1000; diprg.lMax = +1000; if (dijoy[numofjoy]->SetProperty(DIPROP_RANGE,&diprg.diph)!=DI_OK) return(DIENUM_STOP); diprg.diph.dwObj = DIJOFS_Y; if (dijoy[numofjoy]->SetProperty(DIPROP_RANGE,&diprg.diph)!=DI_OK) return(DIENUM_STOP); dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(dipdw.diph); dipdw.diph.dwHow = DIPH_BYOFFSET; dipdw.dwData = 5000; dipdw.diph.dwObj = DIJOFS_X; if (dijoy[numofjoy]->SetProperty(DIPROP_DEADZONE,&dipdw.diph)!=DI_OK) return(DIENUM_STOP); dipdw.diph.dwObj = DIJOFS_Y; if (dijoy[numofjoy]->SetProperty(DIPROP_DEADZONE,&dipdw.diph)!=DI_OK) return(DIENUM_STOP); if (dijoy[numofjoy]->Acquire()!=DI_OK) return(DIENUM_STOP); numofjoy++; if (numofjoy>2) return(DIENUM_STOP); return(DIENUM_CONTINUE);};bool initinput(void){ unsigned char r;//vars if (DirectInputCreateEx(instancehandle,DIRECTINPUT_VERSION,IID_IDirectInput7,(LPVOID *)&dinput,NULL)!=DI_OK) return(false); if (dinput->EnumDevices(DIDEVTYPE_JOYSTICK,EnumJoysticksCallback,NULL,DIEDFL_ATTACHEDONLY)!=DI_OK) return(false); if (dinput->CreateDeviceEx(GUID_SysKeyboard,IID_IDirectInputDevice7,(void **)&dikeyb,NULL)!=DI_OK) return(false); if (dikeyb->SetDataFormat(&c_dfDIKeyboard)!=DI_OK) return(false); if (dikeyb->SetCooperativeLevel(windowhandle,DISCL_EXCLUSIVE/DISCL_FOREGROUND)!=DI_OK) return(false); if (dikeyb->Acquire()!=DI_OK) return(false); return(true);};void checkdevices(void){ unsigned char r;//vars if (dikeyb->GetDeviceState(sizeof(kbbuf),&kbbuf)!=DIERR_INPUTLOST) dikeyb->Acquire(); for (r=0;r dijoy[r]->Poll(); if (dijoy[r]->GetDeviceState(sizeof(joybuf),&joybuf[r])==DIERR_INPUTLOST) dijoy[r]->Acquire(); };};
The only thing I can think of is that it doesn''t accept you to use the keyboard and the joystick at the same time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement