2012-02-03 165 views
4

python可以清除剪貼板嗎?如果是的話......我該怎麼做?清除剪貼板?

我需要這個,所以在我的測驗計劃中,學生無法複製粘貼來自互聯網和其他文件的答案。

編輯:進出口使用的WinXP和Python 2.6

+2

¬¬仍然可以寫下來,不是嗎? – OscarRyz 2012-02-03 02:57:58

+0

類似的問題,相同的基本答案:[我如何從python的(windows)剪貼板中讀取文本?](http://stackoverflow.com/questions/101128/how-do-i-read-text-from-the -windows-clipboard-from-python) – kmote 2012-02-03 02:58:05

+0

@OscarRyz他們可以在他們的答案中輸入 – Katherina 2012-02-03 03:06:53

回答

10
from ctypes import windll 
if windll.user32.OpenClipboard(None): 
    windll.user32.EmptyClipboard() 
    windll.user32.CloseClipboard() 

無需外部庫需要。

+0

嗨,謝謝..這正是我需要的 – Katherina 2012-02-03 08:54:31

1

是的,你可以爲你必須使用PyWin32模塊,它是Windows ectension一個Python模塊。

看看它的EmptyClipboard方法。

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.

+0

嗨,我下載pyWin32。我該如何導入它?即時通訊使用導入win32clipboard,win32con,隨機錯誤。即時獲取此ImportError:DLL加載失敗:指定的模塊找不到。 – Katherina 2012-02-03 03:07:41

+0

@Katherina:下載PyWin32you的哪個版本。下載一個對應於Python2.6的版本 – RanRag 2012-02-03 04:21:57

+0

是的,我確實下載了python 2.6的安裝程序。 idk爲什麼它會在導入時引起我的錯誤。無論如何生病嘗試再次找到它。 – Katherina 2012-02-03 07:36:54