CGEventPost - hold a key (shift)

大憨熊 提交于 2019-12-05 02:18:26
aristidesfl

A shift key virtually pressed that way, will get released automatically when followed by an event which doesn't contain a shift flag. This seems to be a limitation, or possibly a bug, considering the documentation sort of indicates otherwise: https://developer.apple.com/reference/coregraphics/cgevent/1456564-init#discussion

The only way I found to achieve what you are looking for, is to setup an event listener, and add the shift flag to every event which should be modified by the Shift key.

Example on how to listen to keyboard events: https://stackoverflow.com/a/31898592/1445812 (Swift)

Example on how to had the shift flag to intercepted events:

event?.flags.insert(.maskShift)

Hope this helps. If anyone knows how to do the same without having to add the flags to every event, please do tell.

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