How to handle keyboard message sent from wx.TextCtrl?

Dear All,

I want to "bind" a customized message handler to handle the keyboard message
(left/right arrow button down) sent from a wx.TextCtrl. Seems following code
does not work.I dont know why. Any one can tell me how to do that? Thanks in
advance.

# --------------------------------------------------------------
class MyFrame(wx.Frame)
    def __init__(self)
        ....
        txt = wx.TextCtrl( self, ....)
        self.Bind( wx.EVT_KEY_DOWN, self.OnKeyDown, txt)

    def OnKeyDown(self, event )
        ...

Best Regards
Michael

Hi Micheal,

The following should work:

class MyFrame(wx.Frame):
def init(self):

textctrl = wx.TextCtrl(self, -1)
textctrl.Bind(wx.EVT_CHAR, self.OnChar)

    ...
def OnChar(self, event):
    if event.GetKeyCode() == wx.WXK_DOWN:
        print 'its a key down'
    else:
        # Event skipped so goes to textctrl as normal
        event.Skip()

James

···

On Sun, Aug 31, 2008 at 2:25 PM, Michael shushengw@gmail.com wrote:

Dear All,

I want to “bind” a customized message handler to handle the keyboard message

(left/right arrow button down) sent from a wx.TextCtrl. Seems following code

does not work.I dont know why. Any one can tell me how to do that? Thanks in

advance.

--------------------------------------------------------------

class MyFrame(wx.Frame)

def __init__(self)

    ....

    txt = wx.TextCtrl( self, ....)

    self.Bind( wx.EVT_KEY_DOWN, self.OnKeyDown, txt)



def OnKeyDown(self, event )

    ...

Best Regards

Michael


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Michael wrote:

Dear All,

I want to "bind" a customized message handler to handle the keyboard message (left/right arrow button down) sent from a wx.TextCtrl. Seems following code does not work.I dont know why. Any one can tell me how to do that? Thanks in advance.

# --------------------------------------------------------------
class MyFrame(wx.Frame)
    def __init__(self)
        ....
        txt = wx.TextCtrl( self, ....)
        self.Bind( wx.EVT_KEY_DOWN, self.OnKeyDown, txt)

    def OnKeyDown(self, event )
        ...

See self.Bind vs. self.button.Bind - wxPyWiki

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!