nsevent

Adding a global monitor with NSEventMaskKeyDown mask does not trigger

旧城冷巷雨未停 提交于 2021-02-07 04:31:47
问题 I'm working on a MacOS menu bar app which needs to track some global shortcuts in order to facilitate adjusting display brightness on external monitors. However, I cannot get it to fire a handler on any keyboard related events (mouse events work just fine). I'm checking Accessibility with the following code NSDictionary *options = @{CFBridgingRelease(kAXTrustedCheckOptionPrompt): @YES}; BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options); Then, I'm adding a

Adding a global monitor with NSEventMaskKeyDown mask does not trigger

别来无恙 提交于 2021-02-07 04:31:19
问题 I'm working on a MacOS menu bar app which needs to track some global shortcuts in order to facilitate adjusting display brightness on external monitors. However, I cannot get it to fire a handler on any keyboard related events (mouse events work just fine). I'm checking Accessibility with the following code NSDictionary *options = @{CFBridgingRelease(kAXTrustedCheckOptionPrompt): @YES}; BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options); Then, I'm adding a

Stop Mouse Events from queueing while NSMenu is shown

荒凉一梦 提交于 2021-01-28 02:11:24
问题 I have several NSViews that trigger re-draws during the mouseEntered and mouseExited methods. When showing an NSMenu in the same window, updating of those NSViews is suspended (they don't get the mouseEntered and Exited events). My problem is that once the NSMenu is closed (after moving the mouse all over the window outside of the NSMenu), every mouseEntered and Exited event that would have been triggered immediately trigger in a fast sequence. So basically they were queueing up and then

How to judge NSEvent from trackpad click, not tap to click

前提是你 提交于 2021-01-27 13:00:42
问题 When "tap to click" checked, how judge NSEvent is from trackpad click(pressed down) or tap to click. - (void)mouseEvent:(NSEvent*)theEvent { if ((type == NSLeftMouseUp || type == NSLeftMouseDown) && [theEvent subtype] == NSEventSubtypeTouch) { // How to detect touchpad is real pressed?? Not tap to cllick } } 回答1: To find out if someone only "tap to click" you could use func pressureChange(with event: NSEvent) in your NSViewController on NSView. If someone only "tap" the function will not be

How to detect Caps Lock status on macOS with Swift without a window?

淺唱寂寞╮ 提交于 2020-03-05 04:33:53
问题 I have tried KeyDown and NSEvent , but they require a NSWindow object to be active. My hope is that I can put an app on the status bar and alert the user when it has pressed CapsLock , even if the user is in any other app. My app idea doesn't have a window for settings or anything else, is just an indicator. Can it even be done? I am guessing the AppDelegate but can't figure out how to make it receive modifier events. Any help really appreciated! I have looked on stack overflow for a

Right-click on a NSStatusItem

半城伤御伤魂 提交于 2020-02-03 11:01:50
问题 I have a NSStatusItem and I want to popup a menu by rightclicking the item. I subclassed a NSView and overwrote the - (void)rightMouseDown:(NSEvent *)event method. I also implemented - (void)mouseDown:(NSEvent *)event for looking at the modifierflags. My problem is, that the view does not recieve the NSRightMouseDown -Event. And I don't know why? Any ideas how to get this event? Naturally I added the custom view to the statusitem. - UPDATE - Additional information: I have added a NSImageView

How to deal with first responder and a NSPopover

爷,独闯天下 提交于 2020-01-31 08:57:50
问题 I’m trying to replicate the behaviour of the search field in iTunes, for looking up stock symbols and names. Specifically, as you start typing in the search field a popover appears with the filtered items. For the most part I have this working however what I can’t replicate is the way it handles first responder I have my popover appear after three characters are entered. At this point the NSSearchField would lose first responder status and therefore I could no longer continue typing. The

How to deal with first responder and a NSPopover

淺唱寂寞╮ 提交于 2020-01-31 08:56:12
问题 I’m trying to replicate the behaviour of the search field in iTunes, for looking up stock symbols and names. Specifically, as you start typing in the search field a popover appears with the filtered items. For the most part I have this working however what I can’t replicate is the way it handles first responder I have my popover appear after three characters are entered. At this point the NSSearchField would lose first responder status and therefore I could no longer continue typing. The

Inject keyboard event into NSRunningApplication immediately after foregrounding it

天大地大妈咪最大 提交于 2020-01-30 10:50:46
问题 I am trying to bring to foreground a NSRunningApplication* instance, and inject a keyboard event. NSRunningApplication* app = ...; [app activateWithOptions: 0]; inject_keystrokes(); ... fails to inject keyboard events, but: NSRunningApplication* app = ...; [app activateWithOptions: 0]; dispatch_time_t _100ms = dispatch_time( DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC) ); dispatch_after( _100ms, dispatch_get_main_queue(), ^{ inject_keystrokes(); } ); ... succeeds. I imagine it takes a

Inject keyboard event into NSRunningApplication immediately after foregrounding it

≯℡__Kan透↙ 提交于 2020-01-30 10:48:06
问题 I am trying to bring to foreground a NSRunningApplication* instance, and inject a keyboard event. NSRunningApplication* app = ...; [app activateWithOptions: 0]; inject_keystrokes(); ... fails to inject keyboard events, but: NSRunningApplication* app = ...; [app activateWithOptions: 0]; dispatch_time_t _100ms = dispatch_time( DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC) ); dispatch_after( _100ms, dispatch_get_main_queue(), ^{ inject_keystrokes(); } ); ... succeeds. I imagine it takes a