CGEventPost - possible bug when simulating keyboard events?

前端 未结 6 1296
挽巷
挽巷 2020-12-01 05:04

I have a very simple chunk of code that is designed to simulate keyboard events. The simple example below should type \"Cz\" - the shift key goes down, the c key goes down,

6条回答
  •  星月不相逢
    2020-12-01 05:16

    I had a similar problem recently. Instead of passing NULL as the first argument of CGEventCreateKeyboardEvent, create an event source like this:

    CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    

    and use it while you are creating and posting events. CFRelease it when you are done with it.

提交回复
热议问题