#include <linux/joystick.h>
#include<fstream>
#include<iostream>
#include <thread>
enum class xbox_map{
UP,
DOWN,
LEFT,
RIGHT,
X,
Y,
A,
B,
RESET,
START,
NONE
};
void judge_key(js_event& js,xbox_map& data_,int last_value);
using namespace std;
int main()
{
xbox_map data_;
int last_value;
last_value=10;
const char* file="/dev/input/js0";
ifstream fin;
fin.open(file,ios_base::binary | ios_base::in);
struct js_event js;
fstream data;
data.open("data.txt",ios::out|ios::binary);
while (1)
{
fin.read((char *) &js,sizeof(js));
cout<<"time:"<<(int)js.time<<endl<<"number:"<<(int)js.number<<endl<<"type:"<<(int)js.type<<endl<<"value:"<<(int)js.value<<endl;
judge_key(js,data_,last_value);
last_value=js.value;
cout<<"l
c++手柄驱动
最新推荐文章于 2024-09-18 13:33:32 发布
本文介绍了一种使用C++读取并解析Linux下游戏手柄输入的方法,通过监听/dev/input/js0设备,对js_event结构体进行解读,实现对手柄按键和摇杆动作的识别与映射。

最低0.47元/天 解锁文章
1305

被折叠的 条评论
为什么被折叠?



