473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

a question about MS Windows Clipboard to decrease cpu usage.

hello, I want to record the content of windows'clipboad,
after search c.l.p. I got some practical answer such as
http://groups.google.com/group/comp....c5d5fcbd4eb58a
I have create my small script, it can get clipboard preliminary. but
now i had a trouble,
I use win32gui.PumpWaitingMessages() in while True: so the script use
9x% cpu. what should i do?
the code was post below.

##################################################
import win32ui, win32clipboard, win32con, win32api, win32gui
def paste():
win32clipboard.OpenClipboard(0)
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data
class ClipRecord(object):
def __init__(self):
self.hPrev = 0
self.first = True
self.win = win32ui.CreateFrame()
self.win.CreateWindow(None,'',win32con.WS_OVERLAPP EDWINDOW)

self.win.HookMessage(self.OnDrawClipboard,win32con .WM_DRAWCLIPBOARD)

self.win.HookMessage(self.OnChangeCBChain,win32con .WM_CHANGECBCHAIN)
self.win.HookMessage(self.OnDestroy,win32con.WM_DE STROY)
try:

self.hPrev=win32clipboard.SetClipboardViewer(self. win.GetSafeHwnd())
except win32api.error, err:
if win32api.GetLastError () == 0:
# information that there is no other window in chain
pass
else:
raise
while True:
win32gui.PumpWaitingMessages()
def OnChangeCBChain(self, *args):
msg, wParam, lParam = args[-1][1:4]
if self.hPrev == wParam:
# repair the chain
self.hPrev = lParam
if self.hPrev:
# pass the message to the next window in chain
win32api.SendMessage (self.hPrev, msg, wParam, lParam)
def OnDrawClipboard(self, *args):
msg, wParam, lParam = args[-1][1:4]
if self.first:
self.first = False
else:
print "clipboard content changed"
print paste()
if self.hPrev:
# pass the message to the next window in chain
win32api.SendMessage (self.hPrev, msg, wParam, lParam)
def OnDestroy(self):
if self.hPrev:
win32clipboard.ChangeClipboardChain(self.win.GetSa feHwnd(),
self.hPrev)
else:
win32clipboard.ChangeClipboardChain(self.win.GetSa feHwnd(),
0)
if __name__ == "__main__":
cr = ClipRecord()

Oct 22 '06 #1
0 1053

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gey-Hong Gweon | last post by:
Is there a way to copy a PIL image to windows clipboard (as a dib image or a bitmap, I suppose)? What I would like to accomplish is to do a fast copy and paste of images from my python...
0
by: John Benson | last post by:
With respect to: Message: 13 Date: Thu, 1 Jan 2004 18:38:47 -0800 (PST) From: black <quiteblack@yahoo.com> Subject: undo and redo ? To: python-list@python.org Message-ID:...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
2
by: Ronny Sigo | last post by:
Hi all, Could anybody give me the syntax for writing the contents of a textcontrol to the Windows clipboard . (i.e. on the afterupdate event) Any help very much appreciated .... Ronny Sigo
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
0
PEB
by: PEB | last post by:
Hi everybody There is a site about Windows http://www.functionx.com/windows/index.htm :)
0
by: godsmustbcrazy | last post by:
Here is my problem. Brand new SQL Server 2005 Installation 1. Create a database "Test" 2. Create a database user "Domain\user" and set user mapping to "Test" with datareader, datawriter...
4
by: ACF | last post by:
Hello, I'm programming an application in MS Access 2003 / 2007 and would like to know how I can copy highlighted text to the windows clipboard? I am now using a statement in combination with...
2
by: toronto | last post by:
Seasons Greetings Everyone! I want to use JavaScript's event object to detect whether someone has pressed the 'PrintScreen' key to screenshot, via the Windows Clipboard, and to print website...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.