Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to simulate keystroke and mouse movement in Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to simulate keystrokes and mouse movements in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

`

Have you ever had a dream?

-- your computer

Can work for you automatically?

Maybe it's not because

You just saw the Terminator.

However, other than that,

Script and task automation

It is a dream pursued by every advanced user.

If today

There are many solutions.

Can meet this goal.

that

Occasionally

It is difficult to pick from the multitude.

A simple, smart and efficient one

I

You can't pretend.

I found it myself.

And in the meantime,

But prefer that one.

Neat software-- xdotool

The method is so intuitive.

Just as it is revealed as an X11 automation tool

Change of thought

Xdotool can read text files by

Simulate the melody of keystroke

And the mannequin of the mouse

`

Let Xdotool settle in Linux

For Ubuntu,Debian or Linux Mint, you can just do:

$sudo apt-get install xdotool

For Fedora, use the yum command:

$sudo yum install xdotool

For CentOS users, the package can be found in EPEL repo. After enabling the EPEL repository, you can achieve your wish by using the yum command above.

For Arch users, the package can be found in the Community repository:

$sudo pacman-S xdotool

If you still can't find the corresponding xdotool for your distribution, you can download it from its official site.

Basic skills of Xdotool

Although xdotool is so intuitive, it is still a script. Therefore, in order to use it correctly, you still have to understand its grammar. However, please rest assured that compared to the function of the program, grammar is relatively easy to learn.

First, it is easy to simulate keystrokes. You can type the following command from the terminal:

$xdotool key [name of the key]

If you want to connect two keys, you can use the "+" operator between them. It looks like this:

$xdotool key alt+Tab

These two key combinations can switch windows for you.

To get xdotool to type it for you, use the following command:

$xdotool type''

This is enough for basic keystrokes. However, one of the many strengths of xdotool is that it can get the focus of a particular window. It can get the window on the right and enter it, and all the keys you record will not disappear, but will appear there as you wish. To get this feature, a simple command can do it:

$xdotool search-- name [name of the window] key [keys to press]

This command searches for a window with the corresponding name in the open window, focuses on it, and then simulates keystrokes.

Something more advanced, but very useful. Xdotool can simulate mouse movements and clicks. Look at this command:

$xdotool mousemove x y

You can position the cursor to the screen coordinates (in pixels). You can also use the "click" parameter to combine:

$xdotool mousemove x y click 1

This causes the mouse to move to (xrecoery) and then click the left mouse button. "1" represents the left mouse button, "2" is the wheel, and "3" is the right button.

* once you have these commands rooted in your mind, you may want to actually dump them in a file to edit and try to play. In view of this, there will be more than one sentence. All you need is to write a bash script:

#! / bin/bash xdotool [command 1] xdotool [command 2] etc

Or you can use:

$xdotool [filename]

Here you write the command to a separate file, and then use the file name as an argument to the xdotool command.

Unexpected harvest

As a windfall of this article, here is a concrete example of xdotool. You may or may not have heard of Bing, Microsoft's search engine. In later examples, you'll see that you've probably never heard of Bing Rewards: a program that allows you to use Bing points to redeem Amazon gift cards and other gift cards. (LCTT) To earn these points, you can search Bing for a total of 30 times a day, and you will get 0.5 points for each search. In other words, you have to set Bing as the default search engine and use it every day.

Alternatively, you can use the xdotool script, which automatically focuses on Firefox (you can replace it with your favorite browser) and uses the fortune command to generate some random words to perform the search. In about 30 seconds, your daily search task will be complete.

#! / bin/bash for i in {1.. 30} do WID= `xdotool search-- title "Mozilla Firefox" | head-1`xdotool windowfocus $WID xdotool key ctrl+l xdotool key Tab SENTENCE= "$(fortune | cut-d'-F1-3 | head-1)" xdotool type $SENTENCE xdotool key "Return" sleep 4done thank you for reading! This is the end of the article on "how to simulate keystrokes and mouse movement in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report