Simulate keypress using Swift
I'm searching for a way to simulate keystrokes in OSX. I found another solution ( Simulate keypress for system wide hotkeys ) using Objective-C, but i need to do it with Swift. How can i adapt CGEventCreateKeyboardEvent? Airspeed Velocity The code on that linked answer is fairly readily convertible to Swift code, however there are a handful of gotchas you will need to take care of along the way: CGEventSourceCreate takes a CGEventSourceStateID , which is a typealiase for a UInt32 , but the constants such as kCGEventSourceStateHIDSystemState are defined as Int , so you’ll have to cast them i.e.