In Objective-C, When monitoring other apps windows using accessibility APIs, is there a way to know if a window was moved pressing the command key? - objective-c

I am writing a Cocoa Objective-C application for the macOS, and I am using this very good answer here to be notified of window position changes in other applications. Within my app, I can use the event returned by [NSApp currentEvent] to determine the key modifiers. How can I ascertain the same for another app that I am monitoring ? To be simple, I would like to know if a window of an application was moved or resized while pressing the command (or option) key. Many thanks for any help.

Related

Mac development, objective-c: can I detect when user switch tasks like closing a window, activating to another window?

I am developing a desktop application that capture computer activities on mac osx using objective-c. I know it's possible to capture it when user presses on the keyboard and mouse position. But I don't know how to detect when user switches tasks on computer, like closing a window (of other applications), activating another window (of other applications)?
Does anyone have any experience in that?
Yes, via the Accessibility system. For example the NSAccessibilityMainWindowChangedNotification.

How to disable toast notifications in window 8.1 desktop

Now, we are developing a window application for play video like TV.
But When it's running full screen, we must block all window notifications.
so i found many ways to disable notifications.
http://www.maketecheasier.com/disable-toast-notifications-in-windows-8/
But we can't use this way, because it's for only Window App Store Applications.
We want to block all Notifications.
connected USB noti, window update noti, etc.
In addition, Our application has property of the Topmost(base on .net C#).
But it can't Blocked.
is it possible to use the user32.dll??
How to solve it, anyway is ok.
sorry for my poor English. Thanks.

How does "Cinch App" do it?

If you aren't familiar with Cinch, its an application on Mac App Store that allows you to resize ANY window to half/full screen size if you drag the window to the edge of the screen. Exactly like the functionality in windows 7.
Now my question is, how is it done? I have looked all over cocoa apis looking for notifications/delegate methods for whenever a window is being dragged (ALL windows, not just windows owned by the app from which code is running from) but can't find it. Looked in Core Graphics API...Quartz Display Services....but can't find it.
Any help will be greatly appreciated as I have been looking for the past week....Thanks!
Edit: Resize the window is easy since it can be done through applescript bridge..
Are you developer behind i-Snap or some other Mac App Store clone of Cinch?
I'm the developer behind Cinch, and while I try to maintain an "abundance mentality" which basically says "There's enough out there for everyone", I've been upset by the Mac App Store lowering the barrier for entry to this market which has produced a number of half-backed competitors.
I would be thrilled to see some real innovation around the work I have done, and not just clones looking to make a quick buck.
Anyway, you want to look at the Accessibility APIs. It's a Carbon C API. This is probably your best reference: http://developer.apple.com/library/mac/#samplecode/UIElementInspector/Introduction/Intro.html%23//apple_ref/doc/uid/DTS10000728
I've not used the Cinch app, but if I were to do this I'd expect to be using cocoa events. (Also see here) Specifically the mouse handling events, combined with where the mouse is currently on-screen. They probably set a variable when a window is grabbed and then track the mouse pointer until it hits an edge or until they release the mouse button.
Events are very powerful and provide very low level access to what is happening, but can also be very complex. Good luck!
I'm not sure. Maybe the developers combine apple script and carbon events. You can create carbon events to know when the mouse has been clicked or dragged

Cocoa global shortcuts?

I want to create a global shortcut for my app. I've used the 'cool new way' of doing this with the addGlobalMonitorForEventsMatchingMask method. The problem is, my events don't get "consumed": my shortcut includes the spacebar, so whenever I use the shortcut, Quicklook pops up when I'm in the Finder.
How can I prevent this from happening? I know it's possible, because many apps, for example the Bowtie iTunes controller app, do it.
addGlobalMonitorForEventsMatchingMask: is not a suitable replacement for the existing Carbon Hotkey API for all sorts of reasons; it's horribly inefficient, for one. And from the docs:
... you can only observe the event; you cannot modify or otherwise prevent the event from being delivered to its original target application.
and
Key-related events may only be monitored if accessibility is enabled or if your application is trusted for accessibility access
The Hotkey API is still the only way to implement global shortcut in OS X. But unlike many Carbon APIs, the Hotkey API is available to 64-bit apps.
Use the hotkey API, which is meant for this purpose.

Locking a screen in 10.6

How would I go about locking a screen like Keychain does, meaning preventing all access to Dock, menubar, desktop, etc. Basically just a black screen that I can add a password field to, for the user to return to the desktop? I am well aware of the Carbon method, but I want the NSApplication method because this is an all Cocoa application.
Thanks~
If you can get away with not writing this code yourself, all for the better. It is usually a terrible idea to write your own code to lock the screen, considering the number of vulnerabilities that have been found in screen locking code over the years. If you have a Carbon call that can do it, go ahead and use that... don't worry about the "purity" of your Cocoa code.
However, if you decide to write this yourself, here's what you do:
First, capture all the screens using CoreGraphics. See: http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html
Next, create a new NSWindow and put it in front of the window that's used for capturing the screens. You'll have to call a CG function to get the "order" of the black window covering each screen, and order the new window in front of that. Normally, the black window has an order so far forward that everything is behind it. Put a password field in the window. Do NOT use an ordinary text field or write your own code for password input. The password input field has a ton of special code in it so you can't copy text out of it, and other programs can't listen to keystrokes while you're typing into a password field. So use the one that Apple provides.
Last, put the computer in "kiosk mode". This mode allows you to disable alt-tab, user switching, the menubar and dock, and even the ability to force quit. See: http://developer.apple.com/mac/library/technotes/KioskMode/Introduction/Introduction.html
It's not a lot of code, it just uses a few different APIs so you'll spend most of your time bouncing between API docs. I suggest writing the screen lock code as its own application (just add a new application target to your Xcode project) and then put the screen locker inside your application bundle. This used to be (as of 10.4) how Apple Remote Desktop implemented the "Lock Screen" functionality, but I can't find the app anymore.
I believe the Cocoa replacement to the SetSystemUIMode API was not introduced until 10.6.
If you can live with Snow-Leopard-only code, the answer is - setPresentationOptions: on NSApplication.