daily pastebin goal
74%
SHARE
TWEET

Untitled

a guest May 16th, 2018 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var pid: pid_t!
  2.  
  3. override func viewDidLoad() {
  4.     super.viewDidLoad()
  5.  
  6.     let runningApplications = NSRunningApplication.runningApplications(withBundleIdentifier: "com.apple.iphonesimulator")
  7.     pid = runningApplications[0].processIdentifier
  8.  
  9.     NSEvent.addLocalMonitorForEvents(matching: .keyDown) {
  10.         (event) -> NSEvent? in
  11.         self.keyPressDown(with: event)
  12.         return event
  13.     }
  14. }
  15.  
  16. func keyPressDown(with event: NSEvent) {
  17.     print(event.keyCode)
  18.     let cgEvent = CGEvent(keyboardEventSource: nil, virtualKey: event.keyCode, keyDown: true)
  19.     cgEvent?.postToPid(pid)
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top