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


Groups > comp.lang.python > #53899

Re: Monitor key presses in Python?

Path csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
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; 'python.': 0.02; 'subject:Python': 0.06; 'assign': 0.07; 'detect': 0.07; 'arguments,': 0.09; 'callback': 0.09; 'etc).': 0.09; 'events.': 0.09; 'method,': 0.09; 'url:activestate': 0.09; 'python': 0.11; 'systems.': 0.12; 'anyway': 0.14; 'windows': 0.15; 'buttons,': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'portable': 0.16; 'segment': 0.16; 'subject:key': 0.16; 'variables,': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'library': 0.18; 'app': 0.19; 'python?': 0.22; 'header:User-Agent:1': 0.23; 'environment': 0.24; 'sort': 0.25; "i've": 0.25; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'unix': 0.29; 'url:code': 0.29; 'dos': 0.30; "i'm": 0.30; 'code': 0.31; 'libraries': 0.31; 'interface': 0.32; 'run': 0.32; 'running': 0.33; 'display': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; '2.6': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'operating': 0.37; 'message-id:@gmail.com': 0.38; 'handle': 0.38; 'to:addr :python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'course.': 0.60; 'most': 0.60; 'tell': 0.60; "you're": 0.61; "you'll": 0.62; 'email addr:gmail.com': 0.63; 'kind': 0.63; 'box,': 0.64; 'provide': 0.64; 'more': 0.64; 'talking': 0.65; 'etc),': 0.84; 'unix:': 0.84; 'graphical': 0.91; 'shell,': 0.91
X-Virus-Scanned amavisd-new at torriefamily.org
Date Mon, 09 Sep 2013 20:43:34 -0600
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12
MIME-Version 1.0
To python-list@python.org
Subject Re: Monitor key presses in Python?
References <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com>
In-Reply-To <57051d11-abd9-4621-9618-1574cd37545c@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.198.1378781022.5461.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1378781022 news.xs4all.nl 15921 [2001:888:2000:d::a6]:55523
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53899

Show key headers only | View raw


On 09/09/2013 11:39 AM, eamonnrea@gmail.com wrote:
> Is there a way to detect if the user presses a key in Python that
> works on most OS's? I've only seen 1 method, and that only works in
> Python 2.6 and less.  If you get the key, can you store it in a
> variable?
> 
> Also, is there a way to create a callback in Python?

Some python programs display a graphical user interface.  Others run in
a text-mode console (dos prompt, unix shell, etc).  And yet others don't
have any display at all.  If you're talking about a graphical user
interface app (windows, dialogs, buttons, etc), then you'll have to rely
on the particular user interface library you are using to provide that
sort of access.  If you're just running in a dos box, or a unix
terminal, then there are other ways of doing what you want, but I'm not
sure any one way is portable across all operating systems.  I did find
this code segment that claims to work on windows and unix:

http://code.activestate.com/recipes/134892/

Anyway tell us more about what environment and kind of program you are
dealing with.

As for callbacks, of course.  functions are objects in python.  You can
pass them as arguments, assign them to variables, and then call them.
All graphical user interface libraries rely on them to handle events.

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