string/unicode = GetClipboardData(format)

The GetClipboardData function retrieves data from the clipboard in a specified format. The clipboard must have been opened previously. Note that not all data formats are supported, and that the underlying handle can be retrieved with win32clipboard::GetClipboardDataHandle


format=CF_TEXT : int

Specifies a clipboard format. For a description of the standard clipboard formats, see Standard Clipboard Formats. In Unicode builds (ie, python 3k), the default is CF_UNICODETEXT.


An application can enumerate the available formats in advance by using the EnumClipboardFormats function.
The clipboard controls the handle that the GetClipboardData function returns, not the application. The application should copy the data immediately. The application cannot rely on being able to make long-term use of the handle. The application must not free the handle nor leave it locked.
The system performs implicit data format conversions between certain clipboard formats when an application calls the GetClipboardData function. For example, if the CF_OEMTEXT format is on the clipboard, a window can retrieve data in the CF_TEXT format. The format on the clipboard is converted to the requested format on demand. For more information, see Synthesized Clipboard Formats.

Win32 API References

Search for GetClipboardData at msdn, google or google groups.

Search for Standard Clipboard Formats at msdn, google or google groups.

To Do

CF_METAFILEPICT format returns a pointer to a METAFILEPICT struct which contains the metafile handle, rather than returning the handle directly. This code currently fails with error: (6, 'GetClipboardData:GetMetafileBitsEx(NULL)', 'The handle is invalid.')

Return Value

If the function fails, the standard win32api.error exception is raised. If the function succeeds, the return value is as described in the following table:

Format Result type
CF_HDROPA tuple of Unicode filenames.
CF_UNICODETEXTA unicode object.
CF_OEMTEXTA string object.
CF_TEXTA string object.
CF_ENHMETAFILEA string with binary data obtained from GetEnhMetaFileBits
CF_METAFILEPICTA string with binary data obtained from GetMetaFileBitsEx (currently broken)
All other formatsA string with binary data obtained directly from the global memory referenced by the handle.