My apps need to detect that mouse is not having any action or idle for some time to hide a view. I am working on Mac OS X application. Please help
Create a NSTimer that hides the view after x seconds.
Track the mouse by adding a NSTrackingArea on top of your window. Or if you want all events subclass NSApplication and overwrite sendEvent. Reset the timer when you receive an event.
Related
I have an NSView subclass in which I need to detect left and right mouse down events. mouseDown: is working just fine, but rightMouseDown: doesn't fire until the mouse button has been released, at which point both the down and up methods are called in succession. How can I make the right mouse down event trigger its corresponding method immediately?
The problem was that I have a NSPanGestureRecognizer added to the NSView with its buttonMask set to 0x2 (right mouse button). If I remove or disable this gesture recogniser, it allows rightMouseDown: to be called when the right button is pressed down. I'm still trying to figure out why, but at least now I have a starting point.
I'm trying to implement system-wide drag operation with middle mouse button. It should override middle mouse drag behavior in other programs. Currently, I am handling global mouse events with system-wide hooks.
Problem is - many programs still receive and handle same events like I did not intercept them.
Here's what I tried:
not call the next hook for mouse down event: I never receive mouse up, so I don't know where and when to stop dragging
not call the next hook for mouse move: cursor slows down tremendously
not call the next hook for mouse up: most windows in the system stop reacting to mouse events completely after my drag is finished
always call the next hook in the chain: if the control under mouse has scroll in it, most of the time it will be scrolling while my drag is in progress. Also UWP apps continue receiving mouse events during my drag, so if a link in MS Edge happens to be under cursor when it started, and mouse does not leave Edge boundary, Edge receives click event, and new tab is opened
What I need is: when user holds middle mouse and starts dragging, my drag handler should be called, and no other handlers, like file drag, scroll, etc should happen.
I ended up with somewhat hacky solution:
do not call the next hook for mouse down for middle button
record where it was pressed
when handling mouse up, if user did not drag - replay the whole mouse up + mouse down using SendInput from a separate thread (to avoid deadlock due to reentrancy)
I'm trying to capture mouse events on a TScrollBar. In design time, I created a handler for each mouse event, on the Events tab of the Object Inspector. At runtime, the TScrollBar does not fire the mouse events, therefore the handlers are not executed. For instance, when the mouse pointer enters the TScrollBar, the OnMouseEvent never triggers the associated ScrollBarMouseEnter. I'm working with FireMonkey, Berlin 10.1 Update 2, Win32 platform. Any help would be appreciated.
I am writing a custom app using a MKMapView, and I need add a place mark in the map by clicking in the map view, but the mouseDown method is never called. I can not find any doc in the apple developer help.
Place a MKAnnotation is not problem.
Any one can help me with this
You'll need to disable mouse interaction with the MKMapView, by setting the scrollEnabled and zoomEnabled properties to No.
Once those are set the mouseDown and other mouse events fire as expected.
I would like to start a slider action programmatically. So pressing on some text in a NSTextView that displays a slider also automatically starts the mousedown event on the slider so you can drag immediately instead of pressing twice. What approach should i take on this? Should i listen for global mouse events and then manually update the slider position, or can i somehow imitate the systems mouseDown / mouseMoved calls on the NSSlider?