[英]Catching output of linux command in background C++ program / bash script
[英]Background program in C++ for Linux
我不确定应该使用哪些关键字来搜索此关键字,因此我将在这里询问。 很抱歉,如果重复的话。
基本上,我想执行以下操作
./my_prog &
其中my_prog是用C ++ 14编码的,
(这样一来,我每天结束时就能查看我执行上述任何一项操作的频率。)
首先,我想使用Qt,但不久之后我意识到Qt仅在自己的窗口中执行此操作。 (或者至少,这是我所能使用的。)这无济于事,因为我希望让my_prog
对每次单击和按键计数。
有人知道我应该使用哪些库/函数吗? 谢谢。
您需要在Linux中阅读鼠标设备。 在我的Ubuntu中,该设备为“ / dev / input / event4”,您可以从“ / proc / bus / input / devices”检查您的设备。
在linux / input.h标头中,您可以找到可用于处理不同鼠标事件的'input_event'结构。
这是简单的例子
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <linux/input.h>
#define MOUSEFILE "/dev/input/event4"
int main()
{
int fd;
struct input_event ie;
if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
perror("Cannot access mouse device");
exit(EXIT_FAILURE);
}
while(read(fd, &ie, sizeof(struct input_event))) {
printf("%d, %d, %d\n", ie.type, ie.value, ie.code);
}
return 0;
}
您可以从http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/input.h?v=2.6.11.8中找到有关input_event结构和代码定义的更多信息。
例如,在我的机器上,我意识到当我左键单击鼠标时,会发生以下组合
ie.type = 1
ie.value = 1
ie.code = 272
这有助于捕获Linux中的不同事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.