When you need to use CGEvent to create Quartz Event to mimic keyboard input for your macOS program, if you need to mimic the function of shift, control, command, option
, then you need to set flag for CGEvent instance’s flag
property. Meanwhile, if you want to set more than one flag, then you should or the rawvalue
of flag together.
The example is shown here:
1 | let opt1d = CGEvent(keyboardEventSource: src, virtualKey: kVK_Option), keyDown: true) |