cocoa - CGEventPost - hold a key (shift) -
i'm looking way design little panel modifier keys on (shift, command example) , have possibility click on virtual keyboard.
i'd have behavior :
- click on virtual key (shift).
- the shift button holds, , keeps being pressed.
- type standard keyboard.
- click time on virtual shift key release it.
here code i'm using :
cgeventsourceref source = cgeventsourcecreate(kcgeventsourcestatehidsystemstate); cgeventref shiftkeydown = cgeventcreatekeyboardevent(source, (cgkeycode)56, yes); cgeventref shiftkeyup = cgeventcreatekeyboardevent(source, (cgkeycode)56, no); cgeventpost(kcgannotatedsessioneventtap, shiftkeydown); cgeventpost(kcgannotatedsessioneventtap, shiftkeyup); cfrelease(shiftkeyup); cfrelease(shiftkeydown); cfrelease(source);
i can't find way keep pressed until click on time. though "push on push off" button cell type key unfortunately no. :-)
any ?
thanks in advance.
a shift key virtually pressed way, released automatically when followed event doesn't contain shift flag. seems limitation, or possibly bug, considering documentation sort of indicates otherwise: https://developer.apple.com/reference/coregraphics/cgevent/1456564-init#discussion
the way found achieve looking for, setup event listener, , add shift flag every event should modified shift key.
example on how listen keyboard events: https://stackoverflow.com/a/31898592/1445812 (swift)
example on how had shift flag intercepted events:
event?.flags.insert(.maskshift)
hope helps. if knows how same without having add flags every event, please tell.
Comments
Post a Comment