[wxPython] EVT_CHAR_HOOK troubles... (fwd)

316 views
Skip to first unread message

Miles Clark

unread,
Feb 28, 2000, 2:21:29 PM2/28/00
to wxpython-users mailing list

Hi -

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


Robin Dunn

unread,
Feb 28, 2000, 4:07:25 PM2/28/00
to Miles Clark, wxPython-users
>
> 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?
>
>

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!

michael_haider

unread,
Dec 18, 2012, 5:27:48 AM12/18/12
to wxpytho...@googlegroups.com
is there a solution? having the same problem (on win7) linux works already...




--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/wxPython-EVT-CHAR-HOOK-troubles-fwd-tp2270696p5715463.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Robin Dunn

unread,
Dec 18, 2012, 5:13:22 PM12/18/12
to wxpytho...@googlegroups.com
On 12/18/12 2:27 AM, michael_haider wrote:
> is there a solution? having the same problem (on win7) linux works already...
>

Since the message you are replying to is almost 13 years old I doubt
that it really is exactly the same problem. What, exactly, are you
trying to do and why? How are you attempting to do it? What isn't
working? What versions are you using? Can you provide a small,
runnable, standalone application that demonstrates the problem?

http://wiki.wxpython.org/MakingSampleApps

--
Robin Dunn
Software Craftsman
http://wxPython.org

Michael Haider

unread,
Dec 19, 2012, 3:16:35 AM12/19/12
to wxpytho...@googlegroups.com
same bug 13 years later?? :-)

i try to capture all keyboard events sent to a frame. 
Today I detected that in version 2.9.4.0 all works fine but in stable version 2.8.12.1 the "normal" characters (eg. "a","b") are not captured but ("F1","F2",".",",") are captured. (german keyboard)
on my linux (debian) machine 2.8.10.1 is installed and all works fine

attached you find a small example..



2012/12/18 Robin Dunn <ro...@alldunn.com>
test.py

Werner

unread,
Dec 19, 2012, 4:50:59 AM12/19/12
to wxpytho...@googlegroups.com
On 19/12/2012 09:16, Michael Haider wrote:
> same bug 13 years later?? :-)
I doubt as things have changed a lot in the last 10 or so years I use
wxPython.
>
> i try to capture all keyboard events sent to a frame.
> Today I detected that in version 2.9.4.0 all works fine but in stable
> version 2.8.12.1 the "normal" characters (eg. "a","b") are not
> captured but ("F1","F2",".",",") are captured. (german keyboard)
> on my linux (debian) machine 2.8.10.1 is installed and all works fine
>
> attached you find a small example..
I haven't seen the way you do the bind, maybe that is the reason?

This works both on 2.8 and 2.9.5 at least on Windows:
self.tc.Bind(wx.EVT_CHAR_HOOK, self.OnCharHook)
self.tc.Bind(wx.EVT_CHAR, self.OnChar)

And this wiki might help too and I am sure Robin or someone else will
explain it in more detail.

http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind

Werner

Michael Haider

unread,
Dec 19, 2012, 5:05:52 AM12/19/12
to wxpytho...@googlegroups.com
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....

Mit freundlichen Grᅵᅵen


Michael Haider
Hofstᅵdtler IE GMBH
email: michael...@hofstaedtler.com
homepage: http://www.hofstaedtler.com
Tel.: 02622/21550
Fax.: 02622/21550-5


>>> Werner <werner...@sfr.fr> 19.12.2012 10:50 >>>
--
To unsubscribe, send email to
wxPython-user...@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en


This message and any attachment are confidential and may be
privileged or otherwise protected from disclosure. If you are not
the intended recipient, please telephone or email the sender and
delete this message and any attachment from your system. If you
are not the intended recipient you must not copy this message or
attachment or disclose the contents to any other person.

Werner

unread,
Dec 19, 2012, 5:13:31 AM12/19/12
to wxpytho...@googlegroups.com
On 19/12/2012 11:05, Michael Haider wrote:
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....
Check out the wiki page, isn't this the explanation?

wx.Event vs. wx.CommandEvent

First things first. When searching for a binding for a particular event, wxPython will search up the containment hierarchy (parent windows) for events that are instances of wx.CommandEvent, but will not for those that are not. There are several reasons for this, which we won't go into here. Just treat it as a fact of life; be happy and move on.


...

http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind 
Werner

Michael Haider

unread,
Dec 19, 2012, 5:44:14 AM12/19/12
to wxpytho...@googlegroups.com
no....
because in older version it worked ... in newer version it works
in 2.8.12.1 it doesn't....

Mit freundlichen Grᅵᅵen


Michael Haider
Hofstᅵdtler IE GMBH
email: michael...@hofstaedtler.com
homepage: http://www.hofstaedtler.com
Tel.: 02622/21550
Fax.: 02622/21550-5


>>> Werner <werner...@sfr.fr> 19.12.2012 11:13 >>>
On 19/12/2012 11:05, Michael Haider wrote:
> 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....
Check out the wiki page, isn't this the explanation?


wx.Event vs. wx.CommandEvent

First things first. When searching for a binding for a particular
event,
wxPython will search up the containment hierarchy (parent windows) for

events that are instances of *wx.CommandEvent*, but will not for those

that are not. There are several reasons for this, which we won't go
into
here. Just treat it as a fact of life; be happy and move on.


...

> http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind
Werner

Werner

unread,
Dec 19, 2012, 7:10:10 AM12/19/12
to wxpytho...@googlegroups.com
On 19/12/2012 11:44, Michael Haider wrote:
> no....
> because in older version it worked ... in newer version it works
> in 2.8.12.1 it doesn't....
Was intrigued to find out what it should do and did a bit of
documentation search and googling.

According to the docs the EVT_CHAR_HOOK is an exception to the rule and
it should propagate up the hierarchy.

http://wxpython.org/Phoenix/docs/html/KeyEvent.html

But then I found this thread from 12 years ago which more or less says
don't use it. So, maybe that means that the above documentation should
be updated in some form.

https://groups.google.com/forum/?fromgroups=#!topic/wx-users/OBuzhzy2H5s

Werner

BTW, most of us here prefer bottom and/or interspersed posting as it is
easier to follow over time.

Robin Dunn

unread,
Dec 19, 2012, 1:54:59 PM12/19/12
to wxpytho...@googlegroups.com
On 12/19/12 12:16 AM, Michael Haider wrote:
> same bug 13 years later?? :-)

Perhaps. Or at least similar, although I think it may have been other
platforms that were the biggest problems back then.

>
> i try to capture all keyboard events sent to a frame.
> Today I detected that in version 2.9.4.0 all works fine but in stable
> version 2.8.12.1 the "normal" characters (eg. "a","b") are not captured
> but ("F1","F2",".",",") are captured. (german keyboard)
> on my linux (debian) machine 2.8.10.1 is installed and all works fine

Since it's working as you want it in 2.9 I would suggest upgrading
wxPython to that version. The 2.8 series is receiving very little
developer attention these days.

Michael Haider

unread,
Dec 20, 2012, 9:41:38 AM12/20/12
to wxpytho...@googlegroups.com
OK thank you...

>>> Robin Dunn <ro...@alldunn.com> 19.12.2012 19:54 >>>
--
Reply all
Reply to author
Forward
0 new messages