Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

joystick

> 编程语言
Open source

A minimal C++ object-oriented API onto joystick devices under Linux

187 stars0 likes1 views
WebsiteGitHub

About

A minimal C++ object-oriented API onto joystick devices under Linux

joystick++

A minimal C++ object-oriented API onto joystick devices under Linux.

usage

Create an instance of Joystick:

cpp
Joystick joystick;

Ensure that it was found and that we can use it:

cpp
if (!joystick.isFound())
{
  printf("open failed.\n");
  // hmm
}

Sample events from the Joystick:

cpp
JoystickEvent event;
if (joystick.sample(&event))
{
  // use 'event'
}

example

You might run this in a loop:

cpp
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:

cpp
Joystick js0(0);
Joystick js1(1);

Or provide a specific device name:

cpp
Joystick js0("/dev/input/js0");

license

Released under Apache License 2.0.

Copyright Drew Noakes 2013-2017.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言