Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to emulate the cmd-shift-4 screen capture interface?

Tags:

macos

cocoa

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. presents a mouse cursor
  2. mouseDown and drag, mouseUp captures the screen coordinates while drawing a translucent overlay to denote the area being captured

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.

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.

Thanks!

like image 309
ambertch Avatar asked Jan 19 '23 13:01

ambertch


1 Answers

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.

like image 69
Chuck Avatar answered Jan 28 '23 08:01

Chuck