USB Joystick with C++ and DirectInput

元气小坏坏 提交于 2019-12-06 06:37:39

There are a few DirectInput samples in DirectX SDK, source code and compiled binaries. Included is Joystick sample. Older versions of SDK (look for "DirectX 9.0 SDK", years around 2004-2005) had even more samples, up to a dozen!

Joystick Sample


Description The Joystick sample program obtains and displays joystick data.

Path Source: (SDK root )\Samples\C++\DirectInput\Joystick

Executable: (SDK root )\Samples\C++\DirectInput\Bin\Joystick.exe

User's Guide Observe how the displayed data changes when you move and twist the stick, rotate the throttle wheel, and press buttons in various combinations.

Programming Notes The application polls the joystick for immediate data in response to a timer set inside the dialog procedure.

Probably these might help you:

  1. Directinput devices
  2. Coding4Fun joystick

actually Coding4Fun has a lot of interesting things. It began around the time Win7 were released.

I used walbourn/directx-sdk-samples on github and it works perfectly.

I had to configure .pro file as follows to run it on Qt Creator:

TEMPLATE = app
CONFIG += c++14
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp
HEADERS += resource.h
DISTFILES += directx.ico joystick.rc
RC_FILE = joystick.rc

DEFINES -= UNICODE
#DEFINES += _MBCS

win32: QMAKE_CXXFLAGS_RELEASE -= -Zc:strictStrings
win32: QMAKE_CFLAGS_RELEASE -= -Zc:strictStrings
win32: QMAKE_CXXFLAGS_DEBUG -= -Zc:strictStrings
win32: QMAKE_CFLAGS_DEBUG -= -Zc:strictStrings
win32: QMAKE_CFLAGS -= -Zc:strictStrings
win32: QMAKE_CXXFLAGS -= -Zc:strictStrings

LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/um/x64"
LIBS += -lshell32 -luser32 -ldxguid -lcomctl32 -lole32 -loleaut32 -ldinput8
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!