I have a custom NSView implementing keyDown and keyUp methods, but it's actually a plugin and it is desirable to somehow send the keys to the host if the key strokes hasn't been used. Is there a way to safely forward the keyDown/keyUp to the main window of the application?
Related
I have a NSPopover that opens, and if the user clicks somewhere else in the app, the popover closes.
But the problem is that currently that mouseDown event is consumed during the popover-closing process.
Is it possible to still have that mouseDown event go through to the application, but also close the popover?
I had this same problem, so we changed to using NSPopoverBehaviorSemitransient for the behavior type. It no longer steals the mouseDown: and we just added some extra cases for closing the popover manually.
You can subclass the windows contentViewControllers view object.
I did this in the Storyboard file.
In there, implement the mouseDown() method. In there, you can create a notification which can be received at a point in your project where you need to know about the mouse event.
As the 'root view' captures almost all mouseDown() events, you have to filter them in order to only respond to the notification when the popover is displayed.
Don't forget to call super.mouseDown() at the end of your implementation.
Is there any way to detect and respond when a control on a window loses focus?
I want to run some code when a user leaves NSTableView.
Thanks,
You can do this in 10.6 and later by using KVO to observe the window's firstResponder. It will change when the focused control in the window changes.
Put the code you want to run in the observing object's observeValueForKeyPath:ofObject:change:context: method.
What's is the equivalent of window's WM_MOVE in Mac OS ? I have to capture a mouse event when one moves window using left click. In windows we can capture this event using WM_MOVE but i could not find similar event in Mac OS
In Cocoa, look at the NSWindow and NSNotificationCenter classes (or alternately assign a delegate instance to an NSWindow, which receives notifications implicitly just by implementing appropriate methods).
For instance you can use windowWillMove: or windowDidMove: notifications to notice when a window has been moved by the user. This is not sent continuously; it is sent when the user starts moving a window, or pauses while moving the window. If you need fine-grained control over mouse events you can subclass the window and implement methods from its superclass NSResponder.
I have control, subclassed from CDialogBar, it has some buttons(like on toolbar). When I catch WM_LBUTTONDOWN in the CDialogBar class is it a simple way of getting know if mouse was clicked on one of the buttons that are on the control?
CDialogBar class normally hosts regular windowed controls, so when a button is clicked there, WM_LBUTTONDOWN message is sent to this control window, not the dialog window class. So if you want to intercept those messages (if you really do), you need to either subclass the windows and handle their messages, or install a message hook.
You can also use Spy++ tool to see what messages are effectively reaching your CDialogBar window of interest to see if handling them might be a solution to your challenge.
I'm building a little app which needs to recognize if certain keys on the keyboard were pressed. In this case the arrow keys. The app must take action when these keys get pressed, even if it's not the frontmost and has no focus.
Is this possible to do? What would I have to do to receive these keyboard events no matter where they happen?
You do this by registering a hotkey using Carbon's RegisterEventHotKey function. There are also open source libraries available that make this easier, for example SGHotKeysLib.