RedHotChiliPepper wrote:
>
> Also I'm trying to detect the keydown of the "delete" button on my
> macbook's keyboard.
>
> self.fileOlv = FastObjectListViewEdit(panel, -1,
> style=wx.LC_REPORT|wx.SUNKEN_BORDER)
> self.fileOlv.Bind(wx.EVT_KEY_DOWN, self.printCode)
> def printCode(self,evt):
> print evt.GetKeyCode()
>
> Pressing "delete" prints 8
> Pressing "fn" prints 0
> Pressing "delete" + "fn" prints 127
>
> 127 corresponds to the value of wx.WXK_DELETE on my Mac, but I could
> not find any keycode that corresponded to 8.
These are ASCII values (as are most of the non-magic key codes). 127 is
ASCII "rubout" (delete forward), and 8 is control-H, which is
backspace. In my experience, the Mac can be rather schizophrenic about
whether the "Delete" key means Delete or Backspace. You can even
configure things to swap the meaning, and that may be what you are
seeing here.
8 is WXK_CONTROL_H, if you have wx 2.9 or more.
The Fn key is always handled by the hardware. It doesn't generate any
key codes on its own.
> Is there a way I can detect the "delete" key being pressed down
> without someone having to simultaneously press the "fn" key? I'm
> concerned if I bind my handler to the evt.GetKeyCode() of 8 on a Mac,
> that on different types of Macs the value of evt.GetKeyCode() would vary.
Well, what is going to happen when you detect that key code? Are you
going to delete something? Or are you going to backspace over
something? The former should use 127, the latter should use 8. If the
user has configured "Delete" to send "backspace", then presumably they
will know what they did.
>
> What is the best approach to detect events not in the keycode table?
I'm not sure what that means. For the non-special keys, the keycodes
are just ASCII. The constants are just a convenient shortcut.
>
> I also wanted to add that for some reason pressing the "delete" key
> prints 127 instead of 8, as opposed to my above code, when I use this
> code snippet
> import sys
> import tty
> tty.setcbreak(sys.stdin)
> while True:
> print ord(sys.stdin.read(1))
Here, you're getting the system's TTY handling involved. The "stty"
command configures whether the key sends 8 or 127.
--
Tim Roberts,
ti...@probo.com
Providenza & Boekelheide, Inc.