1.使用步骤
1.1 将内容复制进入粘贴板。
1.2 将光标定入想要输入的位置,输入@@@ 等待1s-2s左右就会开始打印
2.代码实现:
"""
Created on 2021-09-30
@author: Jin
note:
本代码仅用于个人学习使用,其他用途造成任何损失,与作者无关。
"""
print("特别说明:")
print("本代码仅用于个人学习使用,其他用途造成任何损失,与作者无关。\n\n")
from pynput.keyboard import Controller, Key, Listener
import win32clipboard as wc
import threading
import time
from threading import Lock
kb = Controller()
CHCKKEY = "@@@"
MAXSIZE = 10000
lock = Lock()
class FQueue:
def __init__(self, size):
self.size = size
self.list = []
def append(self, el):
if len(self.list) == self.size:
newList = []
for i in range(1, self.size):
newList.append(self.list[i])
newList.append(el)
self.list = newList
else:
self.list.append(el)
def check(self, str):
if (len(self.list) < 3):
return False
Flag = True
for i in range(self.size):
if self.list[i] != str[i]:
Flag = False;
return Flag
def clear(self):
self.list = []
queue = FQueue(3)
def on_press(key):
try:
if format(key.char) != None:
queue.append(format(key.char))
if (queue.check(CHCKKEY)):
process()
except AttributeError:
pass
def process():
lock.acquire()
queue.clear()
content = getCopyTxet()
if len(content) > MAXSIZE:
print("超出处理最大长度。。。不给予处理!!!!")
return None
list_text = split_content(content)
time.sleep(1)
i=0;
for line in list_text:
if CHCKKEY in line:
print(line + "内容不合法请重新设置")
return
else:
print(line)
if i==0:
delete_ckeckkey()
outLine(line)
i=i+1;
lock.release()
def delete_ckeckkey():
time.sleep(0.7)
for i in range(len(CHCKKEY)):
kb.press(Key.backspace)
def outLine(line):
list=line.split("\n")
for el in list:
kb.type(el)
def split_content(content, width=100):
list = []
lenth = len(content);
if lenth < width:
list.append(content)
return list
if (lenth % width) == 0:
n = int(lenth / width);
else:
n = int(lenth / width) + 1;
for i in range(n):
if i == n - 1:
if lenth % width == 0:
list.append(content[i * width:(i + 1) * width])
else:
list.append(content[i * width:i * width + (lenth % width)])
else:
list.append(content[i * width:(i + 1) * width])
return list
def on_release(key):
if key == Key.esc:
return False
def start_listen():
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
def getCopyTxet():
wc.OpenClipboard()
copytxet = wc.GetClipboardData()
wc.CloseClipboard()
return str(copytxet)
if __name__ == '__main__':
print("欢迎使用,请将内容复制进粘贴板,按住@@@开始打印复制。。。")
start_listen()
## 代码 代码不足之处,希望大佬个帮忙指出。
|