Is there a way to know what the current system cursor on mac/ OSX is ? I know we can get current cursor using [NSCursor currentSystemCursor] call. But this does not tell us what the current cursor is. The check
if ([[NSCursor currentSystemCursor] isEqual:[NSCursor arrowCursor]]) always fails. Even the check if ([[NSCursor currentSystemCursor] isEqual:[NSCursor currentSystemCursor]]) always returns zero.
I have gone through similar question How to get current type of mouse cursor in Mac OS X? but did not find any way of doing it there.
Any help on this is appreciated. Thanks in advance.
Unfortunately not.
What you can do is get the cursor image and the compare that image to the image of a known cursor (arrow, I-beam, etc).
However many apps supply slight variations of each cursor so your check can never be exhaustive unless you keep updating the app to know about more and more cursor variation.
You can even build an algorithm to analyse the cursor image to heuristically categorise it.
It sounds hacky, I know. But it does work. Kinda.
I was able to get this to work using double equals.
ex:
[NSCursor currentCursor] == [NSCursor arrowCursor]
returns the result I'm expecting. It's annoying that you can't just query the type but at least this worked to set conditional breakpoints and stuff like that.
Hope that helps.
Related
I'm looking for a way to identify if a handle references something on the/a screen (a screen, a window, a control, the entire virtual desktop, etc).
I'm trying to standardise the resolution of the interface so that I can consistently save it and do non-regression testing on it. So I've hooked a couple of system calls like GetDeviceCaps so that I can intercept the resolution and change it to a consistent 96DPI.
So far I've found GetObjectType that doesn't necessarily tell me if the object is part of the screen (comparing to OBJ_DC and OBJ_MemDC). Combining that with WindowFromDC I can get a slightly more indicative result, but it's still not perfect.
I thought maybe I could use EnumDisplayMonitors with null for the first two parameters, but it never seems to function.
Does anyone have a fool proof way of telling if a handle references a screen object or not?
Thank you in advance!
Loren
Turns out I could've used GetDeviceCaps with the parameter index set to TECHNOLOGY. An object related to rendering to a screen will be identified as DT_RASDISPLAY
See https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps
I understand that this question has already been answered:
Detect if cursor is hidden on Mac OS X
But at this point, the function "CGCursorIsVisible" has been deprecated. According to the help literature, there is no replacement.
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/c/func/CGCursorIsVisible
When using the hide and show functions (CGDisplayHideCursor / CGDisplayShowCursor), no reference to the cursor's visibility is returned. Although a show / hide counter is maintained by quartz, there's no way of accessing that value.
So, how do we find out if the cursor is visible or not?
I ran into the very same problem and could not find a valid answer to this problem.
I solved it by implementing a counter which is set to 0 when my application starts. I increase it everytime I hide the cursor and then I can unhide while the _counter != 0.
Your Mac seems to have an own counter for each application... So if your application is not in foreground and it uses the [NSCursor hide] command, it will still be visible but become invisible, when your app becomes keyWindow again.
I know it is a little bit late, but I recently stumbled upon a similar issue. One way to solve this problem is to push an empty cursor onto the cursor stack instead of calling NSCursor.hide() like this:
let myCursor = NSCursor.init(image: NSImage.init(size: NSSize(width: 1, height: 1)), hotSpot: NSPoint(x: 0, y: 0))
myCursor.set()
At a later point in time you can then just push the normal arrow cursor with NSCursor.arrow.set() or NScursor.arrow.push().
This way you don't have the issue of keeping track of the hide/unhide count.
Theoretically you should also be able to check the reference of NSCursor.current against myCursor and see if you still have the invisible cursor (I have not checked this though).
I previously asked a question about changing the cursor system-wide on OSX. I used NSCursor to change the cursor, but the effects are only as long as the application is active. When another application becomes active, the custom cursor is lost.
Here is a related, more general question. How can you write an application to have system-wife effects? For example drawing an image on-screen even when your application is not active, and something else is?
I understand I probably need to go at a lower level than the Cocoa APIs. I just cannot figure out where to start looking? Any specific Carbon APIs that I need to be looking at? Or even lower?
Any pointers would be appreciated! If you specifically know how to change the cursor system-wide or how to draw an image and move it around (no matter what application is active), that would solve my current problem as well! Can I write an application that can achieve this when its installed on the system?
Thanks!
You can achieve the effect you want, but not the way you're thinking about doing it.
You say,
I am writing a presentation aid application that shows the equivalent of the "laser pointer" on screen, programmatically. My first idea was to use the mouse cursor itself as the pointer, and change its appearance as a red circle.
Then fake that. Create an application, perhaps of type LSUIElement, perhaps not, depending on the behavior you want. Create a borderless window (type NSBorderlessWindowMask) and fill it with a clear color. Set its window level high enough so that it floats over everything (using -[NSWindow setLevel:], though I can't think of what the best level would be off-hand), and draw into it.
It's true that you cannot set the cursor when you are not the foremost app. It's true that you cannot just scribble on the screen. But you can get the same effects if you're clever.
This behaviour is not provided by any APIs on Mac OS X. You would have to modify the resource files in the OS, and that's a very dangerous operation that could brick the target computer. You have to know what you're doing.
Are you trying to implement a theming app or something like that? What's your goal? If you tell us what you are trying to do, we may be able to suggest alternate approaches.
I am writing an app with raw windows API (opensource Win32++) where I have a ListView.
The problem I have now is that whenever an item in the ListView is clicked, the system/app will generate a warning tone/sound "ding". Furthermore, I noticed I cannot get the LVN_ITEMACTIVATE through item-dbl-click or item-keypress-enter, which would normally work if this problem had not occur.
Would anyone have any idea how this might be happening?
I believe there is nothing wrong with Win32++, it just could be one of the things I do is causing this. But my program has become quite big to dissect plus I have no idea where to start looking.
Thanks.
PS: I had my computer muted for the longest time, hence, I don't know when this started eventhough I had the listview since a long time ago. T_T
Start looking with a tool that can show you the Windows messages that the control generates and receives. Like Microsoft's Spy++. Compare it with a working list view to have an idea what might be amiss. Also check the parent window. I haven't otherwise heard of listviews that dingaling, the LVN_ACTIVATEITEM should fire the first WM_LBUTTONDOWN, no double-click necessary.
If I have the handles to two windows, how can I tell whether one is obscuring the other? Obviously I can easily do a collision test, but how do I test / find out their "z order"? The windows are from totally different apps.
I am probably missing something fairly obvious..
WindowFromPoint, (use a point bounded by one window, and see if you get back that window's handle, or the other one).
For partial obscuration, you can use the clipping system. I discuss this in more detail on my website here
This page talks about the Z ordering of windows. It doesn't mention a function to get the Z order directly, but it does point at GetNextWindow(), which given one window can return the next (or previous, don't let the name fool you) in the Z order. Using that, you should be able to figure it out.