Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19261

Re: PyHook to catch mouse events

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!newsfeed.xs4all.nl!newsfeed5.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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '#if': 0.07; 'something,': 0.07; 'stuff,': 0.07; 'python': 0.08; 'all?': 0.09; 'also:': 0.09; 'freezes': 0.09; 'handlers': 0.09; 'am,': 0.12; 'def': 0.13; 'gui': 0.13; 'cc:addr:python-list': 0.15; 'ctrl+c': 0.16; 'cursor': 0.16; 'earlier.': 0.16; 'event):': 0.16; 'event-driven': 0.16; 'on).': 0.16; 'somehow,': 0.16; 'subject:events': 0.16; 'system-wide': 0.16; 'win32api': 0.16; 'wrote:': 0.16; 'posting': 0.20; 'cc:no real name:2**0': 0.21; 'input': 0.21; 'header:In- Reply-To:1': 0.22; 'systems.': 0.23; 'starts': 0.24; 'cc:2**0': 0.25; 'windows': 0.26; 'work,': 0.26; 'function': 0.27; 'import': 0.27; 'exit': 0.28; "skip:' 30": 0.28; "skip:' 10": 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'lines': 0.30; '(the': 0.30; 'quite': 0.31; 'does': 0.32; 'done': 0.33; 'header :User-Agent:1': 0.33; 'there': 0.33; 'normally': 0.34; 'programming,': 0.34; 'rule': 0.34; 'skip:# 10': 0.34; 'rather': 0.34; 'scale.': 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; 'using': 0.37; 'cross': 0.38; 'event': 0.38; 'some': 0.38; 'useful': 0.38; 'received:192': 0.38; 'itself.': 0.38; 'doing': 0.39; 'expected': 0.39; 'subject:: ': 0.39; 'your': 0.61; 'details': 0.65; 'mouse': 0.67; 'header:Reply- To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'click': 0.79; '07:06': 0.84; 'experienced,': 0.84; 'freeze': 0.84; 'hook': 0.84; 'to:addr:hotmail.com': 0.89
Date Mon, 23 Jan 2012 08:24: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 <BLU167-W464D9764E6240DDB4B1F92C78A0@phx.gbl>
In-Reply-To <BLU167-W464D9764E6240DDB4B1F92C78A0@phx.gbl>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:jlbKLSR7qu4riKV2g1/ym9WooENl3NCngxzpMTVEYGe ihK0pg93GLhjCqrd0q5rv+obXPjAXMI+XfJCM86/p+hmvtjLY+ RRO++77J5MscWi/R2X8FHd9Dry9sBrY30SE4LCLJAep+N90dcN oPGh1cfTTnqotrKnpTCVHCx+Am7U9RgBBEd3ALofmFOfE9OJPh 0oqVX59tfofaegcoRV1+FTgTupWmkrXpZFQbWol+B6xYD5FSHY asNzQNZw3D1VfL7t0S5+ykJhx2a8zvGz4atRqBdqFhaqbfqzHb Wuwu22z1tinEYugzKzvgSxKqiZDLCdXa69YKlioxoQ3WfnX35F p9U4JLxU8c9KZnFnjQu0=
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.4963.1327325089.27778.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327325089 news.xs4all.nl 6936 [2001:888:2000:d::a6]:45958
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19261

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: PyHook to catch mouse events Dave Angel <d@davea.name> - 2012-01-23 08:24 -0500

csiph-web