Python programming to automatically send messages

The art of speaking is so complicated. If you can't win a conversation with others, you always run out of words at critical moments. So I thought of using python to write a code to make up for my shortage.

In just a few dozen lines of code, automatic message sending is realized

Upper renderings

Functions that control the keyboard

def keyboard_input(string):    # 定义控制键盘的函数
    keyboard = key_con()    # 获取键盘的控制
    keyboard.type(string)   # 定义键盘的类型

Functions that control the mouse

def mouth_input():
    mouth = mouth_con()   # 获取鼠标控制权限
    mouth.press(Button.left)   # 模拟鼠标按下
    mouth.release(Button.left)  # 模拟鼠标左键释放

function to send a message

def send_messadge(number):  # 定义发送的函数
    keyboard = key_con()        # 获取控制权限
    time.sleep(3)
    for i in range(number):
        mouth_input()
        keyboard_input(angry[random.randint(0,len(angry)-1)])  # 随机生成一个列表中的一段骂人的话
        time.sleep(1)
        keyboard.press(Key.enter)   # 模拟键盘enter键按下
        keyboard.release(Key.enter) # 模拟键盘enter键释放

full code

import random
import time
from pynput.keyboard import Key,Controller as key_con  # 导入控制键盘的函数
from pynput.mouse import Button,Controller as mouth_con  # 导入控制鼠标的函数
from random import randint

angry = ["这里你们自己发挥"]

def keyboard_input(string):    # 定义控制键盘的函数
    keyboard = key_con()    # 获取键盘的控制
    keyboard.type(string)   # 定义键盘的类型
def mouth_input():
    mouth = mouth_con()   # 获取鼠标控制权限
    mouth.press(Button.left)   # 模拟鼠标按下
    mouth.release(Button.left)  # 模拟鼠标左键释放
def send_messadge(number):  # 定义发送的函数
    keyboard = key_con()        # 获取控制权限
    time.sleep(3)
    for i in range(number):
        mouth_input()
        keyboard_input(angry[random.randint(0,len(angry)-1)])  # 随机生成一个列表中的一段骂人的话
        time.sleep(1)
        keyboard.press(Key.enter)   # 模拟键盘enter键按下
        keyboard.release(Key.enter) # 模拟键盘enter键释放

send_messadge(10)   # 发送多少条

. My understanding of python is still relatively shallow, the code has many shortcomings, welcome to point out

Guess you like

Origin blog.csdn.net/qq_64047342/article/details/122101708