linux arm下获取屏幕事件(rk3588)
1、找到屏幕设备名称
cat /proc/bus/input/devices
我的屏幕设备是ILITEK ILITEK-TP,它的设备名称是event1.
2、读取屏幕事件。
方法1:
cat /dev/input/event1 | hexdump
方法2:
3、c++代码实现
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
int fd;
fd_set rds;
int ret;
struct input_event event;
struct timeval time;
fd = open( "/dev/input/event1", O_RDONLY );
if ( fd < 0 )
{
qWarning()<<"/dev/input/event1";
return(-1);
}
while ( 1 )
{
FD_ZERO( &rds );
FD_SET( fd, &rds );
/*调用select检查是否能够从/dev/input/event1设备读取数据*/
ret = select( fd + 1, &rds, nullptr, nullptr, nullptr );
if ( ret < 0 )
{
qWarning()<<"select";
return(-1);
}
/*能够读取到数据*/
else if ( FD_ISSET( fd, &rds ) )
{
ret = read( fd, &event, sizeof(struct input_event) );
time = event.time;
qDebug("timeS=%ld,timeUS=%ld,type=%d,code=%d,value=%d\n", time.tv_sec, time.tv_usec, event.type, event.code, event.value );
}
}
/*关闭设备文件句柄*/
close( fd );
return a.exec();
}