利用python进行键盘模拟输入

记一次利用python模拟键盘输入,由于键盘中英文切换较为麻烦,所以写了两个小程序分别进行英文字符模拟或中文字符模拟。

python 复制代码
#用于键盘英文字符输入模拟
import pyautogui
import time


def simulate_typing(text):
    # Give some time to switch to the desired application
    time.sleep(5)

    # Simulate typing each character
    for char in text:
        pyautogui.typewrite(char)
        time.sleep(0.1)  # Adjust the delay between keystrokes if needed

    # Press Enter key at the end
    pyautogui.press('enter')


# 要输入的英文字符
input_text = input("Enter the text : ")
simulate_typing(input_text)
python 复制代码
#用于键盘中文字符输入模拟
from pynput.keyboard import Controller
import time


def type_chinese_text(text):
    keyboard = Controller()
    time.sleep(5)
    for char in text:
        keyboard.type(char)
        time.sleep(0.1)  # Adjust the delay between keystrokes if needed


# 要输入的中文字符
input_text = input("Enter the text : ")

type_chinese_text(input_text)

在第二个程序中,也可以输入英文字符,但是由于系统键盘中英文的切换问题,当进行英文和中文混合使用时,模拟会出现偏差。

相关推荐
跳跳的向阳花8 分钟前
01、大模型部署方案与Dify的使用
python
西柚小萌新27 分钟前
【Python从入门到精通】--Pycharm增加内存
开发语言·python·pycharm
西柚小萌新32 分钟前
【深入浅出PyTorch】--7.1.PyTorch可视化1
人工智能·pytorch·python
我是华为OD~HR~栗栗呀39 分钟前
华为OD-23届考研-Java面经
java·c++·后端·python·华为od·华为·面试
Small___ming1 小时前
【Python基础】Python路径操作全解析:os.path、glob与pathlib从入门到精通
开发语言·python
这里有鱼汤1 小时前
3步用Python识别MACD背驰,避免80%追涨杀跌陷阱,建议收藏
后端·python
程序员爱钓鱼1 小时前
Python编程实战 · 基础入门篇 | Python能做什么
后端·python·github
一车小面包2 小时前
Transformers中从 logits 本质到问答系统中的字符定位机制
pytorch·python·深度学习
战族狼魂2 小时前
基于python+Java的二手车与奔驰销量数据可视化平台
java·数据库·python
Goboy2 小时前
【Python修仙笔记.3】Python函数作为秘技 - 封装你的仙法
后端·python