Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19272
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; '#if': 0.07; 'paths': 0.07; 'say.': 0.07; 'something,': 0.07; 'stuff,': 0.07; 'python': 0.08; 'all?': 0.09; 'also:': 0.09; 'called.': 0.09; 'freezes': 0.09; 'handlers': 0.09; 'loop.': 0.09; 'am,': 0.12; 'def': 0.13; 'library': 0.13; 'gui': 0.13; 'cc:addr:python- list': 0.15; 'mon,': 0.15; 'ctrl+c': 0.16; 'cursor': 0.16; 'earlier.': 0.16; 'event):': 0.16; 'event-driven': 0.16; 'guis': 0.16; 'non-standard': 0.16; 'on).': 0.16; 'somehow,': 0.16; 'subject:events': 0.16; 'system-wide': 0.16; "there'll": 0.16; 'win32api': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'long,': 0.19; 'jan': 0.19; 'trying': 0.20; 'posting': 0.20; 'cc:no real name:2**0': 0.21; 'input': 0.21; 'header:In-Reply-To:1': 0.22; 'systems.': 0.23; '-0500': 0.23; 'starts': 0.24; 'do,': 0.25; 'cc:2**0': 0.25; 'cc:': 0.25; 'windows': 0.26; 'work,': 0.26; 'function': 0.27; 'import': 0.27; 'exit': 0.28; "skip:' 30": 0.28; 'date:': 0.28; "skip:' 10": 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'lines': 0.30; 'generally': 0.30; 'processes.': 0.30; 'queue': 0.30; '(the': 0.30; 'quite': 0.31; 'like.': 0.32; 'does': 0.32; 'familiar': 0.32; 'idea': 0.32; 'done': 0.33; 'header:User-Agent:1': 0.33; 'there': 0.33; 'subject:': 0.34; 'normally': 0.34; 'programming,': 0.34; 'rule': 0.34; 'skip:# 10': 0.34; 'rather': 0.34; 'scale.': 0.34; '(not': 0.34; 'running': 0.35; 'record': 0.35; 'something': 0.35; 'moving': 0.35; 'response': 0.35; 'problem.': 0.36; 'uses': 0.36; 'run': 0.37; 'but': 0.37; "there's": 0.37; 'another': 0.37; 'using': 0.37; 'cross': 0.38; 'posts': 0.38; 'event': 0.38; 'some': 0.38; 'useful': 0.38; 'received:192': 0.38; 'itself.': 0.38; 'from:': 0.39; 'doing': 0.39; 'expected': 0.39; 'subject:: ': 0.39; 'type': 0.60; 'more': 0.61; 'your': 0.61; 'details': 0.65; 'chain': 0.66; 'mouse': 0.67; 'header:Reply-To:1': 0.71; 'email addr:hotmail.com': 0.71; 'reply-to:no real name:2**0': 0.72; 'click': 0.79; '07:06': 0.84; '08:35': 0.84; 'experienced,': 0.84; 'freeze': 0.84; 'hook': 0.84; 'to:addr:hotmail.com': 0.89; 'fast,': 0.91; 'presumably': 0.93 |
| Date | Mon, 23 Jan 2012 13:30:41 -0500 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 |
| MIME-Version | 1.0 |
| To | Neru Yume <neruyume@hotmail.com> |
| Subject | Re: PyHook to catch mouse events |
| References | <4F1D5F99.6010701@davea.name> <BLU167-W34FAFA8FC53290A8F317F2C78A0@phx.gbl> |
| In-Reply-To | <BLU167-W34FAFA8FC53290A8F317F2C78A0@phx.gbl> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:rB1N+1WXbOuhvLxzqxK7lRNPvlgDwb9JHap2kB/z1Ux +MXwzTr6NgSe/p+MRZEW4B6w45YVCYd2lcsDs/EyXaayJyxQx+ fhgmFov+hCjl1xVfmyVHAt7vtZAS1HY5froB25UlqrgCjQPDPj sEIoGDdk/vGULTPmEzuUkiHcK2NFVnepFg8vAlMJvv+jto66sZ OLaC0C243IECYUBGSkXxbK9ubrZPQ75gLnvnk8OxeY/Ozt0g0O +F70hbADzbPoKLbKSfQq1sTnQAWs4PCkse4jZony4oiWj8echy eKwgcL0plYrEaVNo6Kl6ATsfhtNv7O/pnHNwHFvghxYItZrNxw 1ziU1VRFn5ddRhHuYiX8= |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4969.1327343451.27778.python-list@python.org> (permalink) |
| Lines | 90 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1327343451 news.xs4all.nl 6857 [2001:888:2000:d::a6]:36137 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:19272 |
Show key headers only | View raw
On 01/23/2012 08:35 AM, Neru Yume wrote: > >> Date: Mon, 23 Jan 2012 08:24:41 -0500 >> From: d@davea.name >> To: neruyume@hotmail.com >> CC: python-list@python.org >> Subject: Re: PyHook to catch mouse events >> >> On 01/23/2012 07:06 AM, Neru Yume wrote: >>> Using PyHook to record mouse events, one has to add quite a few lines to set up a hook, and as far as I have experienced, if one uses time.sleep() or some other function that spends some time doing something, the program freezes my computer completely while doing this (the cursor starts moving slowly, and so on). >>> >>> >>> Also: Ctrl+c does not work, I have to click the cross to exit the program, which is horrible when combined with the freezing mentioned earlier. >>> >>> >>> Is there a way to avoid the program freezing up? Using the win32api somehow, rather than PyHook? (I only know how to generate input with win32api, not catch output). >>> >>> >>> import pythoncom, pyHook >>> class record(object): >>> def OnMouseEvent(self, event): >>> print 'MessageName:',event.MessageName >>> print 'Message:',event.Message >>> print 'Time:',event.Time >>> print 'Window:',event.Window >>> print 'WindowName:',event.WindowName >>> print 'Position:',event.Position >>> print 'Wheel:',event.Wheel >>> print 'Injected:',event.Injected >>> print '---' >>> #time.sleep(1) #If I uncomment this, running the program will freeze stuff, as mentioned earlier. >>> return True >>> >>> recordit = record() >>> hm = pyHook.HookManager() >>> hm.MouseAll = recordit.OnMouseEvent >>> hm.HookMouse() >>> pythoncom.PumpMessages() >>> >> This is the nature of event-driven systems. When you hook into the >> Windows system, you're expected to carve your event handlers into >> something quick. For normal Python gui programming, breaking the rule >> will only affect your own program. Pyhook just does the same thing on a >> system-wide scale. >> >> >> Are you sure you need global events at all? >> >> If you want to do useful work in response to particular global mouse >> events, you'll have to arrange to get control some other way. Normally >> this is done by posting pseudo-events in your process's message queue, >> so you'll get control again, and can continue working on the problem. I >> don't know the specific details for pyhook, since I don't run Windows >> any more, and pyhook is not part of Python itself. >> >> >> -- >> >> DaveA >> > > > > I do need global events, yes - I am not using any particular GUIs at the moment but rather trying to record mouse paths (not limited to one window). > > > Not very familiar with message queues of processes. > > You're using some non-standard library pythoncom, with a function PumpMessages(), which sounds like an event loop. So presumably that library came with some documentation. Generally there'll be some way to add messages to the pumpmessage queue. So you tell the pumpmessages queue to associate a message type to another event handler you write, then create such a message in your OnMouseEvent. The OnMouseEvent stays fast, but next time through the pumpmessages queue your new handler gets called. It does some work, then if there's more to do, it posts a new message to the same queue. The idea is that no event takes very long, but by using a chain of them, you get to do as much as you like. Since I know nothing about ether pythoncom or pyHook, that's about all I can say. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: PyHook to catch mouse events Dave Angel <d@davea.name> - 2012-01-23 13:30 -0500
csiph-web