Cocoa: Limit mouse to screen - objective-c

I'm developing a kiosk mode application for OSX. In some circumstances, another screen gets attached. My application runs in fullscreen on one screen using:
[self.window.contentView enterFullScreenMode:s
withOptions:[NSDictionary dictionaryWithObject:appOptions
forKey:NSFullScreenModeApplicationPresentationOptions]];
The options are the following:
[NSNumber numberWithUnsignedInt:(NSApplicationPresentationHideMenuBar|
NSApplicationPresentationHideDock|
NSApplicationPresentationDisableHideApplication|
NSApplicationPresentationDisableProcessSwitching|
NSApplicationPresentationDisableAppleMenu)];
What I want is limit the mouse cursor to the screen where the game is running.
How can I accomplish that?

Add an NSTrackingArea to the screens you don't want the mouse entering. When you get notified that the mouse has entered the tracking area, use CGEventCreateMouseEvent and CGPostEvent to move the mouse back to a safe location, probably the nearest point on the main screen.

Related

How to create a NSWindow like iTunes mini player (always on top but get no focus!)

I have a borderless window with a webview in it, which is always on top.
I want to create a NSWindow which is:
Always on top
Does not take the focus from the current foreground app
Does enable user mouse interaction (without forcing the user to switch focus to it - aka "click on it twice")
The problem I have atm is that to interact with the window (e.g. see hover effect, or click a link in the webview), the user has to click the window (which gives it focus) and only then the hover effect shows.
How can I make a window like iTunes mini player which doesn't take the focus from the current app - but also interacts with mouse? (see screenshots below)
Thanks!!
To receive mouseEntered:, mouseMoved: and mouseExited: events even when your app is not active, you must add a tracking area to some view in your window and set the tracking area's properties accordingly.
Take a look at NSTrackingArea.
You'll probably want to add a tracking area with the options NSTrackingActiveAlways and NSTrackingMouseEnteredAndExited.

How can I set background image when half of app screen slides down for the behavior double tap the home button?

I'm finding a way to set a background image when half of app screen slides down. for the behaviour double tap the home button. Can anybody give me some help for this?
That area is not part of the application, but rather a view placed by the operating system.
Think of the double tap as a mechanism for the OS to "shift" your app down for easier access.

Objective-c call touch on screen without user touching the screen

Im going to be using a framework that allows a iphone app to control my app on iPad. When i add it im going to make the joystick move a image of a mouse, and when the user presses the A button, i want to make the device think the user is touching at that point. Is there any way to do this?
Example: I place a button on the ipad screen at 0,0 with height and width of 100. then mouse is at point 50,50 and when the user presses and holds A, that button is held down, and when user lifts up, it calls that buttons action.

Observe global mouse location on screen in Cocoa?

I'd like to be notified when the mouse moves and get the location on the screen. I tried this:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent *event) {
CGPoint location = [NSEvent mouseLocation];
NSLog(#"Position: %#", NSStringFromPoint(location));
}];
However this seems to only work as long as the mouse is in my app's window. As soon as leave it I'm not notified. Until I enter the window again. Shouldn't this event be global?
UPDATE:
I extracted the code in question and made a separate sample project (Dropbox-Link). Just to be sure, there is nothing else interfering with it. It's a clean project with just the code above in applicationDidFinishLaunching:. I get the same results and it's really strange. I uploaded a video to youtube: http://www.youtube.com/watch?v=I3AKgmURaMk.
These are my observations:
Immediately after launching the app, no events at all are delivered, no matter where I move the mouse.
Clicking the app's window will somehow activate event delivery. Now I receive NSMouseMovedMask events, no matter where I move the mouse (this is what I want to achieve).
Clicking back to Xcode doesn't change anything. I keep getting the events.
However, moving the focus back to my app results in a strange behavior. When I move my mouse over Xcode I only get events over some parts of the window, while some parts seem to absorb the event. More specifically I don't receive events over the editor or the log view. I only receive them while moving the mouse over the gray split view separator area (with the tab bars embedded in them).
It should work, I've seen weird behavior when the window is up but not in the foreground. I've noticed that if the application is in the background but not in the dock you will only get events when the mouse transitions between windows in the foreground. Minimizing the application seems to fix this problem.. I'm very new at cocoa dev/ObjC.. I might be wrong, but I've noticed when I minimize my app, I get all events.

App crashes when tapped frequently

I am working on an app for iPad. In one class, I have used a scroll view at the bottom of the screen. This scroll view has some buttons. Those button play a video or open a PDF file. When user frequently taps on those button the app crashes. I have no idea why is it happening. Can any one please tell me why is it happening and how can I fix this crash?
Regards
PC
You should track the state of your view. Which button was pressed last, and don't allow it to be pressed again until.
a) it is done loading the pdf/video
and/or
b) another button has been pressed
You might have to be more strict than that, but we cannot help more than that at this point as Till mentions in your comments