简体   繁体   中英

Simulating key presses aren't working on mac (python)

I have this code which should simulate a key press, but it is not working and I don't know why. My IDE has access to monitor input to the keyboard in system preferences. When I use keyboard.type("sentence") it works but does not type the first two characters. I am very confused as to why. Any help is appreciated

import time
from pynput.keyboard import Key, Controller


keyboard = Controller()
time.sleep(2)
keyboard.press('a')
keyboard.release('a')

Does your IDE have the permission: system preferences/Security & Privacy/Accessibilty? (macOS)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM