如何实现本机MacOS屏幕截图鼠标行为?
我正在实施一个屏幕截图应用程序,该应用程序捕获了屏幕的一部分。我目前:
- 聆听键盘快捷键
- 在整个屏幕顶部绘制透明视图
- ,然后用户单击并拖动以选择该视图内部的区域,
- 以屏幕截图,将该边界区域内部的坐标变为。
这是一个外观的示例(透明视图为有色蓝色):
这可以使鼠标停止关注以前关注的内容。换句话说,如果我在工具提示上徘徊,并且在屏幕截图的快捷方式上打了屏幕截图,则该工具提示在我有机会屏幕截图之前就消失了。
看起来MacOS自己的屏幕快照命令没有这个问题。如果我悬停在stackoverflow中的日期以查看时间工具提示,则可以按CMD+Shift+4,然后很容易地屏幕截图:
如果我尝试使用自己的代码做同样的事情,即使我没有移动鼠标,工具提示也会消失。
苹果是否正在做一些特定的事情来维持我可以做的鼠标的重点状态?另外,我是否应该以某种方式利用苹果自己的屏幕截图流在此应用程序中?如果有帮助,我目前正在使用 >实际拍摄屏幕截图。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论