python - python - 如何在函数运行期间忽略所有用户输入?

50 0

我有一个python模块,它使用pynput监听按键,但是一旦按下它,它就会在一个文本程序中键入一个字符串。

我需要一种方法来禁用键盘,直到pyautogui输完字符串。


from pynput.keyboard import Key, Controller, Listener


import time



keyboard = Controller()



def insert(): # check line 1 of config file 


 keyboard.type('01/20/2019')



# The currently active modifiers


current = set()



def on_press(key):


 if key in COMBINATION:


 current.add(key)


 if all(k in current for k in COMBINATION): # I don't know what this k in current for k shit is.


 current.remove(key)


 insert() # run insert



 if key == Key.esc:


 listener.stop()



def on_release(key):


 try:


 current.remove(key)


 except KeyError:


 pass



with Listener(on_press=on_press, on_release=on_release) as listener:


 listener.join()


``



时间: 原作者:

52 0

你可以在键入之前使用pyautogui.keyUp("shift")


def insert():


f=open('tc.txt')


line=f.readlines()


insert.timestamp=(line[0])


time.sleep(.1)


pyautogui.keyUp("shift")


pyautogui.typewrite(insert.timestamp)



原作者:
...