I sent this a few days ago, with no response. I'm resending in case it
was lost in the ether somewhere.
Is this the way OnCharHook/EVT_CHAR_HOOK is supposed to work, or is there
something wrong with the code?
thanks in advance!
---------- Forwarded message ----------
Date: Fri, 25 Feb 2000 10:44:45 -0800 (Pacific Standard Time)
From: Miles Clark <m...@obispo.com>
To: wxpytho...@server.python.net
Subject: [wxPython] EVT_CHAR_HOOK troubles...
Hi -
I'm attempting to use the CharHook event on a frame to capture all
keyboard events sent to the frame or any of it's child
windows. OnCharHook() is succesfully called for non-printable characters
(Shift, tab, escape, enter, F1, etc), but NOT called for printable
characters ('a', '1', '%', etc.).
I've tried various approaches (using a wxWindow instead of a wxPanel,
using the wxWANTS_CHARS style on the frame, etc.), with no luck.
Any ideas on what I'm doing wrong?
Thanks!
Sample code:
------------
#!/usr/bin/python
from wxPython.wx import *
class MyFrame(wxFrame):
def __init__(self, parent, id, title):
wxFrame.__init__(self, parent, id, title,
wxDefaultPosition, wxSize(400, 400))
self.panel = wxPanel(self, -1)
wxStaticText(self.panel, -1, "wxTextCtrl", wxPoint(5, 25),
wxSize(75, 20))
self.tc = wxTextCtrl(self.panel, 10, "", wxPoint(80, 25),
wxSize(200, 30))
EVT_CHAR_HOOK(self, self.OnCharHook)
EVT_CHAR(self, self.OnChar)
self.panel.Layout()
return
def OnCloseWindow(self, event):
self.Destroy()
return
def OnChar(self, event):
print "OnChar: %d '%c'" % (event.KeyCode(), chr(event.KeyCode()))
event.Skip()
return
def OnCharHook(self, event):
print "OnCharHook: %d" % event.KeyCode()
event.Skip()
return
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(None, -1, 'CharHook Test')
frame.Show(1)
self.SetTopWindow(frame)
return 1
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
_______________________________________________
wxPython-users maillist - wxPytho...@starship.python.net
http://starship.python.net/mailman/listinfo/wxpython-users
_______________________________________________
wxPython-users maillist - wxPytho...@starship.python.net
http://starship.python.net/mailman/listinfo/wxpython-users
Looking at the C++ code it seems that most ASCII keys are being ignored by
the keyhook function. I don't think this is right so I have asked about it
on the wx-devel list.
--
Robin Dunn
Software Craftsman
ro...@AllDunn.com
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/ Check it out!
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
thanks for your answer...
you bind the events to the wx.TextCtrl ...
but i bind it to the Frame, and there happens these things...
self.Bind(wx.EVT_CHAR_HOOK, self.OnCharHook)
I only need to get the EVT_CHAR_HOOK event; EVT_CHAR was only for
testing....
Wernerhttp://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind