Sometimes let the liberation of hands, let the computer to help us automatically send some of the messages we want to send, quite effortless, such as during the day to write a speech, at night in the group text speech, then we can use the script to achieve automatic copy, paste and send text function, so as to liberate ourselves, You don’t have to do Ctrl C/Ctrl V on your computer.
You can also set how long it takes to send the specified content, so you don’t have to sit in front of your computer to click the bullet screen.
How long to send 1 message, or 1 second to send how many pieces of information, can be set freely, time set short words, a second to send dozens of no problem, but too fast will form the effect of brush screen……
Today I’m going to share this technique with you. It’s very simple. There’s not much code.
A, effects,
Let’s take a look at the effect first. I set it to be sent after 4s, with an interval of 0.5s.
[video (video – LQm2vy4y – 1629256154101) (type – bilibili) (url-player.bilibili.com/player.html…)”
Second, development environment
- System: Windows10 64-bit
- Python version: 3.9
- Pycharm version: 2021.1.3
- Modules (libraries) : OS, Time, PyAutoGUI, PyPerClip
Three, key steps analysis
The implementation of the code file mainly has two purposes, respectively: to obtain the location of the chat window and automatic message sending function, using the library has been mentioned above, before starting to write code, the library to be used first PIP download installed, the following will not talk about this.
1. Get the location of the chat window (source 1)
Before we send a message, we need to know where the chat window is, that is, where the mouse stays in order to locate the chat window input interface, that is, what the x and y coordinates of the mouse are.
Here I use OS, Time and PyAutoGUI libraries to get the real-time position of the mouse:
try:
while True:
print("Press Ctrl-C to end")
x, y = pag.position() # return the mouse coordinates
posStr = "Position:" + str(x).rjust(4) + ', ' + str(y).rjust(4)
print(posStr) # print coordinates
time.sleep(0.2)
os.system('cls') # Clear screen
except KeyboardInterrupt:
print('end.... ')
Copy the code
As long as the program is running, every time we move the mouse, the x and Y values of the mouse will automatically change and print out. We just need to bring up the chat window and position the mouse to the input position of the chat window to obtain the X and Y values at this time. With the x and Y values, So we can tell the following messager where to paste and push.
Of course, there are many ways to get the mouse position, but you can also try other ways to get the mouse position.
2. Automatically send messages
After obtaining the values of X and Y, what we need to do is of course to write a program to achieve “copy text → paste text → send message”, here we need to use PyAutoGUI to control the keyboard and mouse, use PyperClip to control the computer to copy and paste, and use the time library to control the time.
First of all, we prepare the content to be sent in advance and put it in the content. Then we can use it directly. The content can be customized and modified, such as:
content = """ Call Uncle Long! The second time! Third time! The fourth time! 5 times! "" "
Copy the code
After running the code, we need to switch to the chat interface, and we need time to do this manually. Therefore, before copying and pasting and sending the code, we need to set some time for ourselves. I set the time delay of 4s here, and of course, we can also set a few hours later to start sending messages.
time.sleep(4)
Copy the code
Here’s how to copy and paste and send:
for line in list(content.split("\n")) *10:
if line:
pyautogui.click(669.687) # Mouse click and position to the chat window
pyperclip.copy(line) # copy this line
pyautogui.hotkey("ctrl"."v") # Paste. On a MAC, change CTRL to Command
pyautogui.typewrite("\n") # to send
time.sleep(5) 5 seconds after each delivery
Copy the code
At this point, everything is done. If 5s is too fast to send a message, you can change the value of 5 in time.sleep(5). If you set it to 0.01 seconds, it will be a quick message sweep effect…..
List (content.split(“\n”))*10 = content.split(“\n”)
Approximate method is above these, I need to source can private chat, you can also try other ways, namely automatic message, there are many kinds of implementation way, such as a more advanced directly with xookie API to send and so on, and the wizard button also can realize the function, more wonderful, waiting for you to dig by himself.
conclusion
The essence of this script is to achieve automatic computer messaging, but the interval Settings lead to it also has the function of fast messaging, not only QQ, wechat can also be used.
This is the basic principle, you can also think about how, on this basis, let the program start after a few hours, every few minutes to send once, completely free yourself.