How can I implement the native macOS screenshot mouse behavior? - swift

I'm implementing a screenshotting app that captures a portion of the screen. I'm currently:
listening for a keyboard shortcut
drawing a transparent view on top of the entire screen
having the user click and drag to select an area inside of that view
screenshotting the coordinates inside of that bounding area.
Here's an example of what it looks like (the transparent view is tinted blue):
This works, but it causes the mouse to stop focusing on whatever it was previously focusing on. In other words, if I'm hovering over a tooltip and I hit the screenshot shortcut, the tooltip vanishes before I have a chance to screenshot it.
It looks like macOS's own screenshot command does not have this problem. If I hover over a date in StackOverflow in order to see the time tooltip, I can press Cmd+Shift+4 and screenshot it pretty easily:
If I try and do the same thing with my own code, the tooltip vanishes after I render my transparent view, even if I haven't moved my mouse.
Is Apple doing something specific to maintain the focus state of the mouse that I could be doing? Alternatively, should I somehow take advantage of Apple's own screenshotting flow myself inside of this app? If it helps, I'm currently using CGWindowListCreateImage to actually take the screenshot.

Related

when UITextField is focused and scribble is on,keyboard don't show

there
I'm making drawing app on iPad with iOS14.
this app enables to use apple pencil.
I'm facing a problem.
when i try to write a text on UITextField by scribble hand write,keyboard don't showing.
my client said it can be enabled keyboard writing when scribble hand write is on.
is it possible?
I'm seeing this quite late but I'll still try to give you (or people looking for the same answer lates) some useful information:
I don't think that you can use "normal" keyboard with pencil (although it will appear immediately after you touch text field with your finger)
You can use pencil to show small screen keyboard by tapping the Scribble toolbar (usually bottom left corner, small icon of pencil tip) and then keyboard button, see here
Hope it will be helpful :)

Microsoft Access Combo Box Arrow Hidden Rectangle Reappears

I have a combo box on a continuous form. I don't want the arrow on the combo box to show unless the record is being changed. I accomplished this by placing a rectangle over the combo box arrow. This works great because it hides the arrow until the record is clicked, then the arrow shows.
The problem is that if you save the form design, close the form, and then open the form, the arrow will reappear and "stick" as you mouse over it. See image below.
The strange thing is that if you open the form, go into design view, and then go back to form view, it no longer "sticks".
Has anyone else had this problem, and if so have you found a work-around?
I did more testing and it turns out there was a little "sliver" of the combobox arrow button peaking out from behind the rectangle. When I expanded the rectangle to cover the entire arrow button, I no longer experienced this problem.

NSButton in Swift, handle click and release events

i'm trying to manage different state of a simple push button on an OS X application : When the user click on it, and when the user release the click.
Currently i set my button type by NSMomentaryLightButton
NSMomentaryLightButton When the button is clicked (on state), it
appears illuminated. If the button has borders, it may also appear
recessed. When the button is released, it returns to its normal (off)
state.
This type of button is best for simply triggering actions because it
doesn’t show its state; it always displays its normal image or title.
This option is called Momentary Light in Interface Builder’s Button
inspector
I thought it was the good way, but when i print my button status, it's like a toggle button than the push button that i set. As you can see on exemple gif
To sum up, How can i have a real push button behaviour ? Call function when the user click on it, and when the user release the click.
Thank,
You don't want to use buttons for piano keys. First, they are non-rectangular, and they don't act as buttons do: neither single-action push-button, nor toggle switches. You are interacting in a custom way, with a custom view, meaning the NSButton control hierarchy isn't called for. Instead you're subclassing NSView and capturing low-level mouse events as detailed here:
https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/10000060i-CH6-SW1
You found this yourself as you detailed in your own comments, but I wanted to make sure you had a higher level point of view. It's even possible, and probably best, to consolidate all of the piano keys into a single view, and let the keys themselves be rendered using NSBezierPath and perform mouse hit detection using containsPoint:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/#//apple_ref/occ/instm/NSBezierPath/containsPoint:
This is a lot more work but the only way to make a truly professional looking piano simulation. Then you can render the keys with whatever outline, fill, and labeling you need without the limitations of built-in button shapes and layout. You could even have the bottom edges of the keys slightly rounded, for example, or apply a shiny texture.

Button with lost focus using PerspectiveTrasnform

Well, I make a Pane based on an example of JavaFX samples (Display Shelf), I put Panes with Labels, Buttons, ComboBox, TableView where's the ImageView. It is working, when I click on Pane, it does the animation correctly, but the buttons that I put in vertical on Right of Pane, receive the focus out of where they are. When I move the mouse button, nothing happens, but if I move the mouse to down of it, I can click in the button that so reveice the focus. The local where I have to move the mouse to button to receive the focus is increasingly far (down) if the button is below the other.
I'm using the Perspective Transform of JavaEX and all is in JavaFX Samples, just changed some params of size (width and height). This effect may be interfering in focus? Or can be another problem? If anyone already had this problem please help me. Thanks.

how to do tooltip on button in iphone?

I am having download icon on my page i want that when the user takes his finger over the button a tooltip should show as showing download in text.
is there any option in iphone to show a tooltip???
Dan is absolutely right on how to do it but I'd answer you should rethink your design to not need the tooltip at all.
There's a reason that there isn't one by default - what if the user presses down on the button to see what it does, reads the tooltip and realises that's not what they want. They then have to be very careful not to let go while still over the button or it will press and do the wrong thing. (And most users don't know that they can press down over a button, move their finger off it and release it to cancel the press.)
You should rethink your design to make it obvious what the buttons do without the user having to interact with them first.
However, if you definitely still want a tooltip, Dan's method is fine.
Nothing built-in, no. If you think about it, generally a tooltip appears when you mouse over the target item. There's no "mousing over" with a touch interface.
You can definitely roll your own, though. Start by placing a view containing your tooltip contents exactly where you want it with an alpha of 0%. Make a custom button with no content that outlines your download icon, and hook its "touch down inside" action to a method that animates the tooltip view to an alpha of 100%. Hook your button's "touch up inside" , "touch down outside" and "touch up outside" actions (and maybe some others--you might want to experiment with that) to a method that animates the tooltip view back to an alpha of 0%.
There isn't native support for this in iOS. But you can create your own.
I ended up creating my custom tooltip/popover class.
Can be initalised with any content view and dynamically adjusts it's frame.
Hope it helps.
https://github.com/akeara/AKETooltip