通过写入/dev/input/mice 来控制鼠标 [英] Control mouse by writing to /dev/input/mice
问题描述
我使用的是 Ubuntu 12.04.对于我的一个应用程序,我需要使用脚本在软件中控制鼠标.
I am using Ubuntu 12.04. For one of my applications I require to control the mouse in software using a script.
我知道鼠标设备是/dev/input/mice
.如果我执行 cat/dev/input/mice
然后移动我的鼠标,我会看到很多输出被转储到屏幕上.
I understand that the mouse device is /dev/input/mice
. If I do a cat /dev/input/mice
and then move my mouse, I see a lot of output being dumped to the screen.
现在我想移除鼠标,并有一个脚本写入 /dev/input/mice
以控制鼠标指针
Now I wish to remove the mouse, and have a script which writes to /dev/input/mice
in order to control the mouse pointer
请帮助我执行以下命令:
(1) 执行左键单击
(2) 执行右键单击
(3) 将鼠标从一个位置移动到另一个位置.
Please help me with commands for the following:
(1) Perform a left click
(2) Perform a right click
(3) Move the mouse from one location to another.
请注意,我正在寻找一个 shell 脚本解决方案,而不是一个 C/C++ 解决方案.
Kindly note that I am looking for a shell script solution, rather than a C/C++ solution.
推荐答案
这不是通过您提到的文件,而是使用此工具更快的方式,而不是破解该文件的转储.它可以在 bash 中完成您想要的一切.
this is not trough the file you mentioned, but its way quicker to use this tool instead of decypering the dump of that file. And it does everything you want in bash.
xdotool 在我的终端中发挥作用.
this 是 ubuntu 的软件包站点.你可能可以安装它
xdotool does the trick in my terminal.
this is the package site for ubuntu.
you probably can install it trough
# apt-get install xdotool
我可以直接在 gentoo 上出现它而不添加任何存储库.
该工具相当简单:
I could just emerge it on gentoo without adding any repositories.
the tool works fairly simple:
#! /bin/bash
# move the mouse x y
xdotool mousemove 1800 500
# left click
xdotool click 1
# right click
xdotool click 3
这篇关于通过写入/dev/input/mice 来控制鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!