How to use CGEventCreateKeyboardEvent in Python on Mac?

I installed pyobjc (with it Quartz) and I would like to know how to correctly create a keyboard event using CGEventCreateKeyboardEvent? You are welcome? I can’t find it at all on the Internet, and even I don’t even know what to import.

Sample code would be nice telling me what to import and what to put in python

Does anyone know the required code for FN (FUNCTION KEY) on mac for CGEventCreateKeyboardEvent ??

+3
source share
1 answer
evt = Quartz.CGEventCreateKeyboardEvent(None, vkey, True)

That is all that is needed.

C, , Python.

CGEventRef event1, event2, event3, event4;
event1 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, true);
event2 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, true);
event3 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, false);
event4 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, false);

Python:

events = [Quartz.CGEventCreateKeyboardEvent(None, 56, True),
          Quartz.CGEventCreateKeyboardEvent(None, 6, True),
          Quartz.CGEventCreateKeyboardEvent(None, 6, False),
          Quartz.CGEventCreateKeyboardEvent(None, 56, False)]

" ", : import Quartz.

, C docs Python, -level Python.

, , Event Taps Testbench. Maverick, Mavericks . , , , , Key Down, Key Up Flags Changed, " " " " , .

+3

All Articles