OSX Controlling the keyboard with Python: hold duration

Multi tool use
Multi tool use


OSX Controlling the keyboard with Python: hold duration



I'm trying to get Python 3.5 to control the keyboard on OS X, using some code I found using Quartz Event Taps.


def KeyPress(k):
keyCode, shiftKey = toKeyCode(k)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(None, keyCode,True))
time.sleep(3.0001)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(None,keyCode,False))



So you would think increasing the x in time.sleep(x) should increase how long the key is held down for, but it does not seem to be working. I have another bit of code that will wait 4 seconds for me to activate another application, like Terminal or TextEdit, and then calls KeyPress('s') to hold down the s key. It prints the s and pauses, but if I actually hold the key down, it would continue to print sssss. So it does not seem to be actually holding the key down, as I would like.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

l19yxVVt5HolRMmVdmHBFcsarFOpM0,uc99f
37EF8B,een P0ECU2 wus

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications