I have a cocoa application where i need to respond to keyDown events during dragging sessions in order to trigger other things. The keys are not modifiers only but can be any kind of key.
The problem is, when i start a dragging session by calling NSWindow.dragImage, i don't get keyDown events during that dragging operation. When i drag an external resource over/into the application window (e.g. a file from Finder) it works fine, NSView.keyDown gets called.
Is there any way of getting around this? Thanks you!
This is probably because the dragging session is using a 'mouse-tracking loop' to handle the drag events. This effectively blocks all other events from being sent to their targets except for the drag events. You can read about this here in the event documentation.
The reason dragging items onto your app does NOT do this is because only the app initiating the drag session is event blocked, not the app receiving the drop.
Having said this, you could try to capture the keyEvents during the mouseDragged event using nextEventMatchingMask:untilDate:inMode:dequeue: this should allow you to pop-off any key events that might be in the event queue.
Also in the documentation linked above they discuss handling key events during mouse drag operations. However the examples don't specifically fit when initiating a drag session with dragImage:at:offset:event:pasteboard:source:slideBack: but you may try watching the performKeyEquivalent as they mention or even seeing if NSWindow's sendEvent: is receiving events during the drag session.
Related
Globals.ThisAddIn.Application.Explorers.NewExplorer += new ExplorersEvents_NewExplorerEventHandler(DoNewExplorer);
I am trying to get the information from an email that I previously opened (by double-clicking) in outlook.
The code works fine until I open multiple emails. What I am finding is that when I click on an email, the inspector activates, but I am getting the information from the last active window, not the current one that I clicked on.
In the Activate event handler you can always call the ActiveInspector method of the Outlook Application class.
Note, the Inspectors collection contains all opened inspector windows, so you could get all of them or find the required one.
Firstly, your code tracks the Explorers.NewExplorer event, not Inspectors.NewInspector.
Secondly, for the Inspectors.NewInspector event, make sure you are using the Inspector object passed to your event handler rather than Application.ActiveInspector: by the time Inspectors.NewInspector event fires, the inspector might not yet be visible/active.
Im trying to create a session timeout when the user is idle for 1 min. I'm planning to use tap event from the topmost page, page-router-outlet (tap)="globalTap()" and reset the timer whenever this tap event is fired. Also, i think i'll add all the user events like swipe, double tap etc. to reset the timer.
Is this the best approach to this problem? Are there sideffects on catching global events on the page router outlet?
Similar question, Detect App inactivity/idle timeout in NativeScript, but Im not keen on the solution because its for android only and it seems like a patch for me.
I want to have the following workflow:
User presses hotkey, or status bar menu button
User clicks on a window
Window is now "registered" in my app
App intercepts mouse events from all registered windows
I've read a lot on CGEvents, CGEventTaps and NSEvents. I can intercept global events and post new ones using CGEvents and CGEventTaps but there is not window information like windowNumber in NSEvent, only PSD (and I'm not sure how to use those), so I can't filter out events from non-registered windows. NSEvent, on the other hand, doesn't let me to intercept global events, only local ones through a localMonitor.
How could I achieve the desired functionality?
You can use the Mac OS X Accessibility API to get details about the currently focused window or application.
The UIElementInspector Apple Sample Code gives many examples.
// Given a uiElement and its attribute, return the value of an accessibility object's attribute.
+ (id)valueOfAttribute:(NSString *)attribute ofUIElement:(AXUIElementRef)element;
Use the kAXFocusedApplicationAttribute or kAXFocusedWindowAttribute attributes with valueOfAttribute:ofUIElement: to get the window/app when you "register" it with your app.
When a CGEvent comes in, compare the currently focused window/app to your list of registered windows/apps to determine if the event should be intercepted.
is there any way to handle the Windows button keypress within the *.Xaml.cs especially when the app is busy getting a request processed using an Asynchronous BeginGetResponse. is there a override handler like OnBackKeyPress?
What's the appropriate way to handle this use case? i'm already handling Application_Activated and deactivated in the App.Xaml.cs file for tombstoning.
You can't stop this from happening. When this happens the current page will get its OnNavigatedFrom override called so you could clean up your page and save state from this method.
Bear in mind that it won't be possible to tell whether this is due to the hardware Start key or if the user just navigated away by say pressing the Back key or tapping a button.
Update:
If you're trying to avoid a crash due to Fast App Switching interrupting your networking call you should rather handle this when you return to the application. Your WebRequest will be cancelled and you should handle this case as shown in this MSDN blog post.
I have an app that subscribes to a specific kind of notifications from the default NSNotificationCenter.
On OSX Lion, it works fine, except that when the app loses the focus (another app becomes active), it stops receiving the events. When the app gains the focus, it starts receiving events again.
The app did not have this behavior on previous versions of OSX, it always received notifications, even when it was out of focus.
What can I do to change this behavior?
Thanks!
Nathan
I know its a bit late to answer this, still for my records and if some one still searching.
My OS X Menu bar app had the same problem. I wanted the app to observe all states.
Reason:
When the app looses focus,the observer is suspended.
ie. When the application becomes in-active it calls the method
-(void)applicationDidResignActive:(NSNotification *)notification
and by default the NSDistributedNotificationCenter object gets suspended.
Solution:
I created an object for NSDistributedNotificationCenter
NSDistributedNotificationCenter *center=[NSDistributedNotificationCenter defaultCenter];
and then when the app looses focus its call the applicationDidResignActive method and inside
that the NSDistributedNotificationCenter object is made to regain from suspended state by sending NO to setSuspended method.
-(void)applicationDidResignActive:(NSNotification *)notification
{
[center setSuspended:NO];
}
and then app starts observing even when it looses focus.
According to NSDistributionNotificationCenter reference
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/Reference/Reference.html#//apple_ref/doc/uid/20000396-BCICEHHB
The NSApplication class automatically suspends distributed notification delivery when the application is not active. Applications based on the Application Kit framework should let AppKit manage the suspension of notification delivery. Foundation-only programs may have occasional need to use this method.
You can either
set the observer's behavior when suspended to NSNotificationSuspensionBehaviorDeliverImmediately using
- (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(NSString *)notificationSender suspensionBehavior:(NSNotificationSuspensionBehavior)suspendedDeliveryBehavior
or set deliverImmediately to YES when posting
- (void)postNotificationName:(NSString *)notificationName object:(NSString *)notificationSender userInfo:(NSDictionary *)userInfo deliverImmediately:(BOOL)deliverImmediately
to send notifications immediately under suspended state.
And make sure you're not periodically killing distnoted.
I forgot I had an old launch agent script to killall distnoted to avoid memory leaks.
It looks like the default behavior when adding an observer to a NSDistributedNotificationsCenter has changed to NSNotificationSuspensionBehaviorCoalesce, that does not deliver notifications when the app is inactive.
Described here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/Reference/Reference.html#//apple_ref/doc/uid/20000396-5567