- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试使用绝对坐标移动光标。这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include <signal.h>
#define die(str, args...) do { \
perror(str); \
exit(EXIT_FAILURE); \
} while(0)
int fd;
static void signal_handler(int signo)
{
printf("\nCaught SIGINT\n");
if(ioctl(fd, UI_DEV_DESTROY) < 0)
die("error: cannot destroy uinput device\n");
else printf("Destroyed uinput_user_dev\n\n");
close(fd);
exit(EXIT_SUCCESS);
}
int
main(void)
{
struct uinput_user_dev uidev;
struct input_event ev;
int x, y;
int i;
if(signal(SIGINT,signal_handler)==SIG_ERR)
{
printf("error registering signal handler\n");
exit(EXIT_FAILURE);
}
fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
if(fd < 0)
die("error: open");
if(ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0)
die("error: ioctl");
// if(ioctl(fd, UI_SET_KEYBIT, BTN_MOUSE) < 0)
// die("error: ioctl");
if(ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_EVBIT, EV_REL) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_RELBIT, REL_X) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_RELBIT, REL_Y) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_EVBIT, EV_ABS) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_ABSBIT,ABS_X) < 0)
die("error: ioctl");
if(ioctl(fd, UI_SET_ABSBIT, ABS_Y) < 0)
die("error: ioctl");
memset(&uidev, 0, sizeof(uidev));
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-sample");
uidev.id.bustype = BUS_USB;
uidev.id.vendor = 0x1;
uidev.id.product = 0x1;
uidev.id.version = 1;
uidev.absmin[ABS_X]=0;
uidev.absmax[ABS_X]=1023;
uidev.absfuzz[ABS_X]=0;
uidev.absflat[ABS_X ]=0;
uidev.absmin[ABS_Y]=0;
uidev.absmax[ABS_Y]=767;
uidev.absfuzz[ABS_Y]=0;
uidev.absflat[ABS_Y ]=0;
if(write(fd, &uidev, sizeof(uidev)) < 0)
die("error: write0");
if(ioctl(fd, UI_DEV_CREATE) < 0)
die("error: ioctl");
sleep(2);
while(1)
{
printf("\nEnter the absoulte x(0-1023) and y(0-767) co-ordinates:");
scanf("%d %d",&x,&y);·······
memset(&ev, 0, sizeof(struct input_event));
gettimeofday(&ev.time,NULL);
ev.type = EV_ABS;
ev.code = ABS_X;
ev.value = x;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
die("error: write1");
memset(&ev, 0, sizeof(struct input_event));
ev.type = EV_SYN;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
die("error: write4");
memset(&ev, 0, sizeof(struct input_event));
ev.type = EV_ABS;
ev.code = ABS_Y;
ev.value = y;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
die("error: write2");
memset(&ev, 0, sizeof(struct input_event));
ev.type = EV_SYN;
if(write(fd, &ev, sizeof(struct input_event)) < 0)
die("error: write3");
usleep(15000);
printf("\nWritten x:%d y:%d to uinput.Press CTRL-C to quit:",x,y);
}
if(ioctl(fd, UI_DEV_DESTROY) < 0)
die("error: cannot destroy uinput device\n");
close(fd);
return 0;
}
程序似乎通过 uinput 将我输入的绝对坐标发送到内核的输入核心。
启用 evbug 后,我在 dmesg 上验证了这一点。但是我的鼠标指针不会在屏幕上移动。我想知道我搞砸了什么。
也许 EV_ABS 没有绑定(bind)到光标?我想知道是因为使用 EV_REL 移动光标工作正常,如 this tutorial 中所述.
样本运行:
ravi@linux-lxaf:~/workspace/driver> sudo ./a.out
Enter the absoulte x(0-1023) and y(0-767) co-ordinates:100 200
Written x:100 y:200 to uinput.Press CTRL-C to quit:
Enter the absoulte x(0-1023) and y(0-767) co-ordinates:10 765
Written x:10 y:765 to uinput.Press CTRL-C to quit:
Enter the absoulte x(0-1023) and y(0-767) co-ordinates:^C
Caught SIGINT
Destroyed uinput_user_dev
Dmesg 输出:
ravi@linux-lxaf:~/workspace/driver> dmesg |grep input16
[ 4750.660420] input: uinput-sample as /devices/virtual/input/input16
[ 4750.660594] evbug.c: Connected device: input16 (uinput-sample at unknown)
[ 4761.389036] evbug.c: Event. Dev: input16, Type: 3, Code: 0, Value: 100
[ 4761.389047] evbug.c: Event. Dev: input16, Type: 0, Code: 0, Value: 0
[ 4761.389053] evbug.c: Event. Dev: input16, Type: 3, Code: 1, Value: 200
[ 4761.389058] evbug.c: Event. Dev: input16, Type: 0, Code: 0, Value: 0
[ 4776.893126] evbug.c: Event. Dev: input16, Type: 3, Code: 0, Value: 10
[ 4776.893138] evbug.c: Event. Dev: input16, Type: 0, Code: 0, Value: 0
[ 4776.893144] evbug.c: Event. Dev: input16, Type: 3, Code: 1, Value: 765
[ 4776.893148] evbug.c: Event. Dev: input16, Type: 0, Code: 0, Value: 0
[ 4778.729711] evbug.c: Event. Dev: input16, Type: 0, Code: 0, Value: 1
[ 4778.745506] evbug.c: Disconnected device: input16
最佳答案
我刚刚发现输入核心将 EV_ABS 值作为绝对值传播到设备节点,正如从阅读/dev/input/eventX 中发现的那样(看起来很明显 现在 !)。所有一直以来,控制光标(X11?)的应用程序在我给它绝对值时期待鼠标的相对移动,这可能使它感到困惑!
关于linux - 使用 uinput 在 Linux 中模拟绝对鼠标移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5190921/
我想要做的是在每个框的蓝色标题之后获取红色文本。 看来我必须添加另一个 div?我已经添加并修改了 .card-indus img 的位置,但结果永远不是我想要的。 你知道为什么即使我将 positi
所以我一直在努力掌握绝对和相对定位的诀窍。关于这个主题有很多教程和问题,我已尽力理解它们。除了这一点,我大部分时间都很好。我正在创建一个页面,其中有较小的缩略图图像,用户可以选择单击并展开图像。为此,
下面是我正在处理的代码。如您所见,有一个“#parent”div 和一个“#child”div。 '#child' div 有一个未定义的高度,这是因为有时,'#child' 的高度小于或长于它的父级
我目前正在创建一个看起来有点像这样的固定 header 。 https://gyazo.com/e0bab8ba195e33110b19123c7fc3c568 Logo 始终位于左侧,小按钮始终位于
我怎样才能得到一个绝对定位的子 div,当它放在父 div 的范围之外时不显示? https://jsfiddle.net/knp9ebys/9/ .papa { background:red;
如果我对 CSS 显得相当“菜鸟”,我深表歉意。我一直在尝试设置以下... #0 { width: 100%; height: y; border: 1px solid black; } #
很长一段时间以来,我一直在摆弄一个特定的布局问题,但我显然采用了错误的方式。 以下是分解为基本组成部分的方法: SOME HEADER
我创建了几个虚拟 Controller ,我希望能够从当前的 http 请求中获取 url。 例如: http://www.site.com/app_1/default.aspx ===> http:
我创建了几个虚拟 Controller ,我希望能够从当前的 http 请求中获取 url。 例如: http://www.site.com/app_1/default.aspx ===> http:
我想知道是否有一个库在某处提供受新类型保护的 FilePath 类型。我找到了我想要的http://hackage.haskell.org/package/darcs-2.8.4/docs/src/D
如果我尝试使用以下方式连接到我的嵌入式数据库: private static String url = "jdbc:sqlite:~/hr4413/pkg/sqlite/Models_R_US.db"
所以我是 django 的新手,我一直在研究 PHP CodeIgniter,其中将绝对 URL 放入 href 我通过调用 URL 帮助程序使用了一个名为 base_url 的函数 它给出的输出类
我有一个小问题。 我在其他 div 中有一些图像元素的容器 div。像这样的东西: 我需要将容器垂直居中,但我不能使用顶部:-healfHeight; mar
我有一个带有 inline-block css 位置的列表(div)。里面有一个 relative 定位的 ul 是隐藏的。所以我试图通过添加一些类将这个 div 转换为 absolute 。通常,当
我正在尝试设置一个卡住列,唯一需要解决的问题是同一行上其他 td 的高度不会扩展以匹配绝对定位 td 的高度。由于卡住标题中的文本是任意的,它可以跨越多行。 如果它不是绝对定位的,那么这将迫使同一行中
这个问题在这里已经有了答案: Centering text vertically and horizontally in a div (1 个回答) 关闭 5 年前。
当它的位置绝对时,我试图使一个框宽度为 100%? 下图是我想要做的 https://i.imgur.com/qMaT361.gif float .box1 { position:re
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我有 3 个 div,都是 positioned: absolute,但是我想要填充窗口宽度的 div 只会适应其中文本的长度。我希望黄色 div #help 填充窗口的其余部分。 我知道这听起来很菜
这个问题在这里已经有了答案: Retrieve the position (X,Y) of an HTML element (32 个答案) 关闭 8 年前。 有时候,当我请求某个对象的.posit
我是一名优秀的程序员,十分优秀!