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

I am creating an OSX application and would like to capture part of the screen using a similar interface, such as CMD-shift-4 UX, IE, the trigger action:

  • represents the mouse cursor
  • mouseDown and drag, mouseUp fixes the coordinates of the screen when drawing a translucent overlay to indicate the captured area.

I found a good starting point at http://code.google.com/p/captureme/ which represents the NSPanel and captures the area inside the panel. However, I would like to improve and imitate the cmd-shift-4 interface a bit.

I can not find if something like this is built in (or if there is an existing solution). I assume that the direct way is to use NSRsponder and replace the cursor with mouseDown, then for the drag event, draw a translucent rectangle between the mouseDown point and the current cursor location. Let me know if my thoughts match the right lines.

Thank!

+3
source share
2 answers

Here's a short version of what you want to do: create a full-screen transparent window in CGShieldingWindowLevel (), setIgnoresMouseEvents:NOhave a view that places the cursor on everything you want, and drag and drop to draw an area in the drag area.

+4
source

screencapture. :

NSTask* task = [[NSTask alloc] init];
[task setArguments: [NSArray arrayWithObject: @"-ic"]];
[task setLaunchPath: @"/usr/sbin/screencapture"];
[task launch];
[task waitUntilExit];
[task release];
NSData* data = [[NSPasteboard generalPasteboard] dataForType: NSPasteboardTypePNG];

, , :

[task setArguments: [NSArray arrayWithObjects: @"-i", filePath, nil]];
+4

All Articles