Button and Key Event

A

akameswaran

assuming you have a button instantiated and named myButton

in 2.6 (namespace is relevant I think prior to 2.4 you had a diff
namespace for wx) for this example i am guessing you are creating the
button as part of a panel or some other object you are extending (ie
self)



self.myButton.Bind(wx.EVT_KEY_DOWN, self.OnLeftDownHandler )





Make sure you define a method OnLeftDownHandler on the parent object.

As a further thought is this really what you are trying to do?
Or do you want to know if a key is pressed when someone clicks on the
button? Check the mouse events, I know you can check if control or
shift was pressed during a mouse click, not sure if you can do any
arbitrary key. Binding the key event will not accomplish that if that
is what you want to know, well you might be able to torture around to
it if that's what you want. The other problem is the key event should
only register if the button has keyboard focus - kind of an odd
situation. So you may want to place the key listener on the parent
object.


Or you may want to look into creating a custom event. Hope this helps.
Also be warry of behavior of evt_char in windows. Can't remember what,
but there is something funky there - I'm sure that was helpful ;)
 
L

lux

Thanks,
I think that the solution for my problem is only to use an
AcceleratorTable.
In this way I can capture the key pressed event
without the "button problem"

Luca
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top