I realised that on OS X it is almost impossible (or at least I can't
find a way) to capture F-key or meta-key presses using the python
curses module.  The following email has some code which illustrates
the problem (it reports key-presses in 3 different ways).  For some
reason I don't understand it works on Linux but not OS X.  Thomas
Dickey from the bug-ncurses list points out that python may be using
its own functions rather than those from curses itself.  At any rate,
this seems to be a mac issue, so I thought I'd point it out here.

Best wishes,

N.

---------- Forwarded message ----------
From: Thomas Dickey <[EMAIL PROTECTED]>
Date: Apr 15, 2006 8:19 PM
Subject: Re: more OS X oddities
To: Nicholas Cole <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]


On Sat, Apr 15, 2006 at 04:20:36PM +0200, Nicholas Cole wrote:
> Why does this code give the name of function keys on linux, but not on
> OS X? I can't work out any way of capturing a function-key press
> (either in X11 or Terminal.app) on OS X.
>
> Best, N.
>
> #!/usr/bin/python
> import curses
> import curses.ascii
>
> def mainloop(scr):
>         while 1:
>                 scr.keypad(1)
>                 ch = scr.getch()
>                 try:
>                         scr.erase()
>                         scr.addstr(0,0, "%s, %s,  %s" %
>                         (curses.keyname(ch), curses.ascii.unctrl(ch), ch))

Checking a little -

The python package for curses does not use the curses function unctrl(),
and uses this chunk instead:

def unctrl(c):
    bits = _ctoi(c)
    if bits == 0x7f:
        rep = "^?"
    elif bits & 0x20:
        rep = chr((bits & 0x7f) | 0x20)
    else:
        rep = "^" + chr(((bits & 0x7f) | 0x20) + 0x20)
    if bits & 0x80:
        return "!" + rep
    return rep

(that accounts for the odd format of the output).

--
Thomas E. Dickey <[EMAIL PROTECTED]>
http://invisible-island.net
ftp://invisible-island.net


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFEQTlJcCNT4PfkjtsRArYrAKC/gk25beCJVHfQC/7vkCLjNNbtjACeJsoC
xo+OWVMpY1lq5SyW26yeDiU=
=DcUE
-----END PGP SIGNATURE-----
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to