[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: more OS X oddities
From: |
Thomas Dickey |
Subject: |
Re: more OS X oddities |
Date: |
Sat, 15 Apr 2006 14:19:53 -0400 |
User-agent: |
Mutt/1.5.9i |
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 <address@hidden>
http://invisible-island.net
ftp://invisible-island.net
signature.asc
Description: Digital signature