CAPTURING KEYBOARD EVENTS[KEYPRESSE]

I was wondering how to bind a key on the keyboard to a function in my wxpython program and also to a button in my program.I have read the documentation so what i really need are simplified examples.Also does anyone know how to play a sound from your python program as fast as possible.I know how to play sounds i just need them to play faster.

···

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Please don't use caps in subject lines, it's rude.

I was wondering how to bind a key on the keyboard to a function in my
wxpython program and also to a button in my program.I have read the
documentation so what i really need are simplified examples.

As I stated 3 days ago, you can bind key down/key up events to a
wx.Panel. More specifically...

class myPanel(wx.Panel):
    def __init__(self, ...):
        ...
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
        ...
    def OnKeyDown(self, evt):
        #information about the keypress is in evt
    def OnKeyUp(self, evt):
        #information about what key was released is in evt

To see examples of this in use, download the wxPython docs and demos
from wxpython.org and see the "Process and Events" -> "KeyEvents" demo.

Also does anyone
know how to play a sound from your python program as fast as possible.I know
how to play sounds i just need them to play faster.

What do you mean "faster". Do you mean when you tell the sound to play,
you want your program to be able to do something else while it is
playing? Or do you want, for example, a 1 second sound file to play in
1/2 second in its entirety?

If it's the former, when you use wx.Sound and call it's .Play() method,
make sure to pass the wx.SOUND_ASYNC flag.

If it's the latter, you need to process the sound yourself. There are
many libraries out there that do sound processing in every language.
Again, use google.

- Josiah

···

"JOSHUA ABRAHAM" <dynamobigjosh@hotmail.com> wrote:

Josiah Carlson wrote:

Please don't use caps in subject lines, it's rude.

I was wondering how to bind a key on the keyboard to a function in my wxpython program and also to a button in my program.I have read the documentation so what i really need are simplified examples.

As I stated 3 days ago, you can bind key down/key up events to a
wx.Panel. More specifically...

class myPanel(wx.Panel):
    def __init__(self, ...):
        ...
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
        self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
        ...
    def OnKeyDown(self, evt):
        #information about the keypress is in evt
    def OnKeyUp(self, evt):
        #information about what key was released is in evt

To see examples of this in use, download the wxPython docs and demos
from wxpython.org and see the "Process and Events" -> "KeyEvents" demo.

Keep in mind that the panel will need to have the focus in order for the key events to be sent to these handlers. If some other widget has the focus then it will be the one that gets the key events instead.

···

"JOSHUA ABRAHAM" <dynamobigjosh@hotmail.com> wrote:

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