Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 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.

See Question&Answers more detail:os

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...