Monday, November 16, 2015

Using the Windows Clipboard

The Windows Clipboard may be very useful for transferring information for processing in quick python scripts.

To this purpose, we are going to use the "win32clipboard" library, included in python distribution.

First, we have to call the library, as usual:

import win32clipboard

Then, in the code, we have to open the Clipboard:

win32clipboard.OpenClipboard()

Once opened, we can retrieve information that is in the Clipboard, copy information to it, or clear all contentents.

To get information in Clipboard, and store its information in a variable:

clipbVar = win32clipboard.GetClipboardData()

To set it to any value:

win32clipboard.SetClipboardText('testing 123')

To clear the Clipboard:

win32clipboard.EmptyClipboard()

After using the Clipboard, we have to close it, as following:

win32clipboard.CloseClipboard()


No comments:

Post a Comment