How to simulate Caps Lock keystroke with CGEventCreateKeyboardEvent in OS X

核能气质少年 提交于 2019-12-04 14:31:20

Do you need to actually toggle the caps lock state, or is merely turning the LED on/off sufficient? If it's just the LEDs, there's some sample code at:

https://github.com/mikeash/mikeash.com-svn/blob/master/CPUFlash/keyboard_leds.c

Note that it doesn't involve CGEvent at all -- it uses IOKit magic to mess with the keyboard LEDs directly.

Haha! This might just be a classic.. Your code exits because it was really able to do anything at all. Add some sleep(seconds)'s here and there. Also try putting a small delay (usleep(microseconds)) in between the down and up events.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!