百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
J

joystick

> 编程语言
开源

Linux 下最小的 C++ 面向对象的 API 到乐杆设备

187 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Linux 下最小的 C++ 面向对象的 API 到乐杆设备

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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