如何模拟cmd-shift-4屏幕捕获界面? [英] How to emulate the cmd-shift-4 screen capture interface?

查看:114
本文介绍了如何模拟cmd-shift-4屏幕捕获界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建OSX应用程序,并希望使用与cmd-shift-4 UX类似的界面来捕获屏幕的一部分,即IE启动操作:

I am building an OSX app and would like to capture a portion of the screen with a similar interface as the cmd-shift-4 UX, IE initiating the action:

  1. 表示鼠标光标
  2. mouseDown并拖动,mouseUp捕获屏幕坐标,同时绘制一个半透明的叠加层以表示要捕获的区域

我在 http://code.google.com/p/中找到了一个很好的起点captureme/会显示一个NSPanel并捕获面板中的区域.但是,我想做得更好一些,并模拟cmd-shift-4界面.

I've found a good starting point in http://code.google.com/p/captureme/ which presents an NSPanel and captures the area within the panel. However I'd like do a bit better and emulate the cmd-shift-4 interface.

我找不到是否内置了这样的东西(或者是否有现有的解决方案).我想直接的方法是使用NSResponder并在mouseDown上替换光标,然后在发生鼠标拖动事件时,在mouseDown点和当前光标位置之间绘制一个半透明的矩形.让我知道我的想法是否正确.

I can't find if something like this is built in (or if there's an existing solution). I suppose the straight forward way is to use an NSResponder and replace the cursor on mouseDown, then on a mouse drag event draw a translucent rectangle between the mouseDown point and the current cursor location. Let me know if my thinking is along the correct lines.

谢谢!

推荐答案

这是您想要做的简述:在CGShieldingWindowLevel()创建一个全屏透明窗口,setIgnoresMouseEvents:NO,将视图设置为任何游标根据需要进行拖动,以在拖动区域中绘制选取框.

Here's the nutshell version of what you want to do: Create a fullscreen transparent window at CGShieldingWindowLevel(), setIgnoresMouseEvents:NO, have the view set the cursor to whatever you want, and implement dragging to draw the marquee in the dragged area.

这篇关于如何模拟cmd-shift-4屏幕捕获界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆