Joystick
A minimal C++ object-oriented API onto joystick devices under Linux
Install / Use
/learn @drewnoakes/JoystickREADME
joystick++
A minimal C++ object-oriented API onto joystick devices under Linux.
usage
Create an instance of Joystick:
Joystick joystick;
Ensure that it was found and that we can use it:
if (!joystick.isFound())
{
printf("open failed.\n");
// hmm
}
Sample events from the Joystick:
JoystickEvent event;
if (joystick.sample(&event))
{
// use 'event'
}
example
You might run this in a loop:
while (true)
{
// Restrict rate
usleep(1000);
// Attempt to sample an event from the joystick
JoystickEvent event;
if (joystick.sample(&event))
{
if (event.isButton())
{
printf("Button %u is %s\n", event.number, event.value == 0 ? "up" : "down");
}
else if (event.isAxis())
{
printf("Axis %u is at position %d\n", event.number, event.value);
}
}
}
This produces something similar to:
Button 1 is up
Button 2 is down
Axis 0 is at position 122
Axis 1 is at position -11
Axis 2 is at position 9796
Axis 3 is at position -13850
options
You can specify the particular joystick by id:
Joystick js0(0);
Joystick js1(1);
Or provide a specific device name:
Joystick js0("/dev/input/js0");
license
Released under Apache License 2.0.
Copyright Drew Noakes 2013-2017.
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.6kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
