Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

linux - Control mouse by writing to /dev/input/mice

I am using Ubuntu 12.04. For one of my applications I require to control the mouse in software using a script.

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.

Now I wish to remove the mouse, and have a script which writes to /dev/input/mice in order to control the mouse pointer

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.

Kindly note that I am looking for a shell script solution, rather than a C/C++ solution.

question from:https://stackoverflow.com/questions/20595716/control-mouse-by-writing-to-dev-input-mice

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 does the trick in my terminal.
this is the package site for ubuntu. you probably can install it trough

# apt-get install xdotool

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

found it here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...