I’ve been trying to experiment with the EmulateKeyPress() method in the TextCtrl class.
It doesn’t behave the way I think it should, but then I’m not sure exactly what it should do.
I found an example program that Robin posted somewhere, and it doesn’t work any better for than what I had been trying.
I've been trying to experiment with the EmulateKeyPress() method in the
TextCtrl class.
It doesn't behave the way I think it should, but then I'm not sure
exactly what it should do.
I found an example program that Robin posted somewhere, and it doesn't
work any better for than what I had been trying.
Which platform?
You will probably have more luck with wx.UIActionSimulator. Instead of programatically decoding the key event and stuffing the characters into the widget it will actually send the low level events that the system would have sent in response to the user's actions. That means that your key event handler will probably be called for them so you will need to either disconnect the handler temporarily, or write the handler to ignore events while processing action simulator events.
def OnKeyDown(self, evt):
key = evt.GetKeyCode()
print chr(key)
if key != ord('X'):
evt.Skip()
return
for char in " FUNKY ":
evt.m_keyCode = ord(char)
self.EmulateKeyPress(evt)
OTOH, if all you need is to stuff in some text at the current position then you could just do this: