how to capture key pressing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • billie

    #1

    how to capture key pressing

    Hi all. I'm searching for a module that permit me to costantly log every key
    pressed on the keyboard and eventually assign it a function (e.g. when "esc"
    is pressed: exit program").


  • Philippe C. Martin

    #2
    Re: how to capture key pressing

    Hi,

    Look at curses.

    Philippe


    billie wrote:
    [color=blue]
    > Hi all. I'm searching for a module that permit me to costantly log every
    > key pressed on the keyboard and eventually assign it a function (e.g. when
    > "esc" is pressed: exit program").[/color]

    Comment

    • billie

      #3
      Re: how to capture key pressing

      > Look at curses.

      I was searching for something portable on multiple platforms.
      Curses doesn't work on Windows.


      Comment

      • Tim Roberts

        #4
        Re: how to capture key pressing

        "billie" <mlist@fastwebn et.it> wrote:[color=blue]
        >[color=green]
        >> Look at curses.[/color]
        >
        >I was searching for something portable on multiple platforms.[/color]

        Keyboard access is not portable. It is quite system-specific, even in C.
        [color=blue]
        >Curses doesn't work on Windows.[/color]

        Sure it does. You can find curses implementations for Windows. However,
        it depends on what you are planning to do. If all you want to do is wait
        for one character and print it, it's not too hard to have separate schemes
        for separate systems:

        C:\Data\PyTools >python
        Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
        win32
        Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
        >>> import msvcrt
        >>> msvcrt.getch()[/color][/color][/color]
        '\x1b'[color=blue][color=green][color=darkred]
        >>>[/color][/color][/color]

        (I pressed "escape" after the second "enter".)
        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        Working...