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


Groups > comp.lang.python > #54179

Re: Monitor key presses in Python?

From Dave Angel <davea@davea.name>
Subject Re: Monitor key presses in Python?
Date 2013-09-14 22:03 +0000
References <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com> <l0n9n1$kpu$1@reader1.panix.com> <5c59400c-45ca-40f0-846c-05bef3eb0233@googlegroups.com> <roy-B7F251.14034214092013@news.panix.com> <bf7b8085-4994-4006-ad66-3ee4d291114e@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.381.1379196255.5461.python-list@python.org> (permalink)

Show all headers | View raw


On 14/9/2013 14:10, eamonnrea@gmail.com wrote:

> I didnt wanna say that, in case people threw a fit and stuff.
>
> So yeah, how would I monitor the key presses?

There's a huge difference between monitoring key presses within your own
process, and intercepting them system-wide.  if you need to see
keystrokes even when your window does not have the focus, then you need
to call some system DLL function, (some kind of "system hook", which
you can probably do using the platform module, or the ctypes module, or
some module that I wouldn't have on Linux.  This type of code is not the
least bit portable, which just means I can't test things here to try to
help.

Note also that if you get one of the ActivePython implementations from
ActiveState, you'll get PyWin32, which may well have a function just for
the purpose.  See:

http://docs.activestate.com/activepython/2.5/pywin32/PyWin32.HTML

I'm sure it can be separately downloaded, but when I used to run
Windows, I just got the whole package.  The ActivePython also had the
best offline documentation I was able to find at the time.

See also Tim Golden's win32 web page:

http://timgolden.me.uk/python/win32_how_do_i.html

There is a separate win32 mailing list;  see:

https://mail.python.org/mailman/listinfo/python-win32

Possibly the most frequent poster there is Tim Golden, so search his
site first.


-- 
DaveA

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


Thread

Monitor key presses in Python? eamonnrea@gmail.com - 2013-09-09 10:39 -0700
  Re: Monitor key presses in Python? Dave Angel <davea@davea.name> - 2013-09-09 18:19 +0000
  Re: Monitor key presses in Python? John Gordon <gordon@panix.com> - 2013-09-09 18:40 +0000
  Re: Monitor key presses in Python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-09 23:37 +0000
  Re: Monitor key presses in Python? Nobody <nobody@nowhere.com> - 2013-09-10 02:33 +0100
  Re: Monitor key presses in Python? Michael Torrie <torriem@gmail.com> - 2013-09-09 20:43 -0600
  Re: Monitor key presses in Python? Grant Edwards <invalid@invalid.invalid> - 2013-09-10 14:18 +0000
    Re: Monitor key presses in Python? eamonnrea@gmail.com - 2013-09-14 10:44 -0700
      Re: Monitor key presses in Python? Roy Smith <roy@panix.com> - 2013-09-14 14:03 -0400
        Re: Monitor key presses in Python? eamonnrea@gmail.com - 2013-09-14 11:10 -0700
          Re: Monitor key presses in Python? Dave Angel <davea@davea.name> - 2013-09-14 22:03 +0000
      Re: Monitor key presses in Python? Paul Rubin <no.email@nospam.invalid> - 2013-09-14 11:42 -0700

csiph-web