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)



原作者:
...