当前位置:   article > 正文

利用python进行键盘模拟输入_python 模拟键盘输入

python 模拟键盘输入

利用python进行键盘模拟输入
python打包分发工具:setuptools

#用于键盘英文字符输入模拟
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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
#用于键盘中文字符输入模拟
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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

遇到回车键也能持续输入
https://www.cnblogs.com/programmer4027/p/14687119.html
python中iter方法_深入了解Python iter() 方法的用法
https://blog.csdn.net/weixin_39559804/article/details/110830564

问题:图标不显示
https://www.ico51.cn/
打包后可能会出现程序图标未生效的情况,原因可能有如下:
1、未使用ico文件作为图标文件
2、准备好的ico文件无效,可能是通过直接修改后缀名的图片文件。
处理办法:
下载ico文件作为图标,或者利用专门的转换工具将png、jpeg等图片文件转换成ico文件。比如格式工厂之类的。

pyinstaller  -y -F -n demo_max -i D:\favicon_max.ico .\main.py
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/601072
推荐阅读
相关标签
  

闽ICP备14008679号