开发者

how to set focus on NSMenu (make it get key events)?

开发者 https://www.devze.com 2023-01-13 00:22 出处:网络
I have a status menu with a NSSearchField and menu items.开发者_如何学编程 When search field is active and user presses up & down arrows, I\'d like to start menu tracking, that is that the user wi

I have a status menu with a NSSearchField and menu items.开发者_如何学编程 When search field is active and user presses up & down arrows, I'd like to start menu tracking, that is that the user will be able to move with arrow keys between menu items. I can catch moveUp and moveDown selectors. How can I cause the menu to become a key responder?

Thanks,

Nava


Fire a kCGEventMouseMoved event on mouseUp/Down. Show/hide cursor on your choice... The main challenge here is find the right origin (global mouse point). Someone has an idea how to find a NSMenuItem rect?

CGEventRef mouseEvent = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, NSPointToCGPoint(globalOrigin) , kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, mouseEvent);
CFRelease(mouseEvent);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号