Reputation: 2223
Is it possible for python to clear the clipboard? If so ... how can I do it?
I need this so in my quiz program, students can't copy paste answers from the internet and other files.
EDIT: Im using WinXP and Python 2.6
Upvotes: 5
Views: 9918
Reputation: 9041
from ctypes import windll
if windll.user32.OpenClipboard(None):
windll.user32.EmptyClipboard()
windll.user32.CloseClipboard()
No external libraries needed.
Upvotes: 11
Reputation: 49597
Yes you can for that you have to use PyWin32
module which is a python module for windows ectension.
Take a look at its EmptyClipboard method.
The EmptyClipboard function empties the clipboard and frees handles to data in the clipboard. The function then assigns ownership of the clipboard to the window that currently has the clipboard open.
Upvotes: 1