欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python 监控扫码枪输入

程序员文章站 2022-06-14 23:03:38
...

用python监控键盘扫描枪输入的内容

from pynput import mouse,keyboard
CODE = ""
# 处理键盘输入的数据
def on_release(key):
    global CODE
    try:
        CODE += key.char
    except Exception as e:
        try:
            if key == key.enter:
                if "http" in CODE:
                    message = CODE.replace("http;","http:")
                    print(message)
                    CODE = ""
        except Exception as e:
            CODE = ""

#监听键盘扫码枪输入
with keyboard.Listener(on_release=on_release) as listener:
    listener.join()
相关标签: Python python