nsevent

In OSX, how to determine which keyboard generated an NSEvent?

无人久伴 提交于 2019-12-10 14:22:07
问题 I've been trying to determine (from within the event handler) which keyboard triggered the event. I've been using these two posts: http://www.cocoabuilder.com/archive/cocoa/229902-which-keyboard-barcode-scanner-did-the-event-come-from.html http://www.cocoabuilder.com/archive/cocoa/274586-getting-keyboard-type-carbon-vs-cg.html#274586 In the second article, the author successfully separate out his keyboards using a Carbon technique, but attempting the same trick using Cocoa fails. On my own

Detect left and right click events on NSStatusItem (Swift)

回眸只為那壹抹淺笑 提交于 2019-12-08 08:10:45
问题 I’m building a status bar app and want to call different actions depending on if the user clicked left or right. Here’s what I have so far: var statusItem = NSStatusBar.system().statusItem(withLength: -1) statusItem.action = #selector(AppDelegate.doSomeAction(sender:)) let leftClick = NSEventMask.leftMouseDown let rightClick = NSEventMask.rightMouseDown statusItem.button?.sendAction(on: leftClick) statusItem.button?.sendAction(on: rightClick) func doSomeAction(sender: NSStatusItem) { print(

NSButton image shadow on mouseEntered event

自闭症网瘾萝莉.ら 提交于 2019-12-07 20:16:54
问题 I have a borderless NSButton that contains an image and is subclassed with my ButtonEffect class to detect mouseEntered and mouseExited events. My goal is to have just the edge of the image glow as the mouse enters the button area. I know I can achieve this by using two different images (one with shadow and another without) but I need to do this with one image. Here's an example of what I hope to achieve for the mouseEntered event: And here's what it should look after the cursor leaves the

keyUp event heard?: Overridden NSView method

浪子不回头ぞ 提交于 2019-12-07 14:41:02
问题 UPDATED: I'm now overriding the NSView keyUp method from a NSView subclass set to first responder like below, but am still not seeing evidence that it is being called. @implementation svsView - (BOOL)acceptsFirstResponder { return YES; } - (void)keyUp:(NSEvent *)event { //--do key up stuff-- NSLog(@"key up'd!"); } @end --ORIGINAL POST-- I'm new to Cocoa and Obj-C and am trying to do a (void)keyUp: from within the implementation of my controller class (which itself is of type NSController). I

mouseEntered event disabled when mouseDown (NSEvents Mac)

做~自己de王妃 提交于 2019-12-07 13:40:13
问题 I have created an NSButton class, and when rolling over my buttons it happily detects mouseEntered and mouseExited events. But as soon as the mouseDown event occurs, so long as the mouse it down, mouseEntered events are no longer called until the mouse button is lifted. So, when the mouseDown event is called, mouseEntered or MouseExited events are no longer called, nor is mouseDown called when rolling over other buttons until I let go of the initial mouseDown. So I would like to detect when

How to monitor for swipe gesture globally in OS X

青春壹個敷衍的年華 提交于 2019-12-06 08:35:31
问题 I'd like to make an OSX application that runs in the background and performs some function when a swipe down with four fingers is detected on the trackpad. Seems easy enough. Apple's docs show almost exactly this here. Their example monitors for mouse down events. As a simple test, I put the following in applicationDidFinishLaunching: in my AppDelegate . void (^handler)(NSEvent *e) = ^(NSEvent *e) { NSLog(@"Left Mouse Down!"); }; [NSEvent addGlobalMonitorForEventsMatchingMask

NSButton image shadow on mouseEntered event

牧云@^-^@ 提交于 2019-12-06 07:12:35
I have a borderless NSButton that contains an image and is subclassed with my ButtonEffect class to detect mouseEntered and mouseExited events. My goal is to have just the edge of the image glow as the mouse enters the button area. I know I can achieve this by using two different images (one with shadow and another without) but I need to do this with one image. Here's an example of what I hope to achieve for the mouseEntered event: And here's what it should look after the cursor leaves the button area: Here's my attempt by setting the background of the cell but it changes the color of the

mouseEntered Event Disabled When mouseDown (NSEvents Mac)

两盒软妹~` 提交于 2019-12-06 03:44:16
I have created an NSButton class, and when rolling over my buttons it happily detects mouseEntered and mouseExited events. But as soon as the mouseDown event occurs, so long as the mouse it down, mouseEntered events are no longer called until the mouse button is lifted. So, when the mouseDown event is called, mouseEntered or MouseExited events are no longer called, nor is mouseDown called when rolling over other buttons until I let go of the initial mouseDown. So I would like to detect when my mouse enters while the mouse is down as well. Hope you understand, and hope you can help stop this.

keyUp event heard?: Overridden NSView method

核能气质少年 提交于 2019-12-05 22:47:18
UPDATED: I'm now overriding the NSView keyUp method from a NSView subclass set to first responder like below, but am still not seeing evidence that it is being called. @implementation svsView - (BOOL)acceptsFirstResponder { return YES; } - (void)keyUp:(NSEvent *)event { //--do key up stuff-- NSLog(@"key up'd!"); } @end --ORIGINAL POST-- I'm new to Cocoa and Obj-C and am trying to do a (void)keyUp: from within the implementation of my controller class (which itself is of type NSController). I'm not sure if this is the right place to put it, though. I have a series of like buttons each set to a

Device Information from NSEvent/CGEvent

别来无恙 提交于 2019-12-05 06:21:53
问题 My application uses an event tap to capture keyboard events, and I'd like to know which device (i.e. which keyboard) each event comes from. Is there an sort of device-identifying information along with the CGEvent that a tap gets? I've looked at NSEvent's methods, and the various CGEventField keys, but none of them seem to be device-unique. Any help? 回答1: You might want to take a look at DDHidLib, Dave Dribin's excellent framework to work with USB HID devices independently. http://www.dribin