The key to taking screenshots with DCOP is use of the slotGrab
command, as shown below:
$
dcop ksnapshot-23151 interface slotGrab
This will take a snapshot using the current snapshot mode and timeout settings
(as described above). If you want to save the snapshot image, there are a
number of calls you can use. If you just want to save the image to the current
path (as returned by url
) or changed by
setURL
), you can call slotSave
, as shown
below:
$
dcop ksnapshot-23151 interface slotSave
If you want the user to be able to specify a filename (and path), you can use
slotSaveAs
, which will bring up a standard KDE file
save dialog.
If you want to save the image to a different name (or path) without
changing the path with setURL
, you can use
save
, providing the URL to save to as an argument. So if you
want to save the snapshot to file:///tmp/tempshot.png
, you
can do the following:
$
dcop ksnapshot-23151 interface save file:///tmp/tempshot.png
Note that this will return true if the snapshot was successfully saved, and false
otherwise. Also, you should be aware that if the file already exists, the user
will get a standard KDE dialog that requires the user to decide whether to overwrite
or not.
In addition to saving the snapshot, you can also copy it to the clipboard, using
the slotCopy
command, as shown below:
$
dcop ksnapshot-23151 interface slotCopy
If you need to select a window that may not be under the mouse cursor, you
can use the slotMovePointer
call, passing the x position
(in screen pixels) and the y position (also in screen pixels) as arguments.
So to move the mouse to the top left hand corner of the screen (0,0), you
can do the following:
$
dcop ksnapshot-23151 interface slotMoveMouse 0 0