How to prevent TextCtrl.EmulateKeyPress to change focus

Hello
Is it possible to have a text control react on a KeyEvent (created
one, not originated from keyboard), but without giving it focus? Or
if giving a focus is needed than is it possible to restore focus
after?

I am working on a hardware device that lets single computer to have
several keyboards attached to it. Purpose of this is to let several
users to type simultaneously to a single computer but to separate
TextCtrl-s.

I wished to make a small program to experiment with. I made frame with
two text controls and bind the EVT_KEY_DOWN in the one of them with
the method OnKeyDown. In that method I tried to create another
KeyEvent object and to set its attributes according to received event,
and than to send it to another text control using EmulateKeyPress
method. It worked as expected, but it also changed focus to another
text control. So that next key press was directed to the second text
control.

You could try using WriteText instead of emulating the keypress, I
don't think it fires a focus event.

Or you could handle EVT_FOCUS and veto the event following input from
a keyboard to prevent it taking focus..

- mh

···

On Mar 4, 7:12 am, Виталије <vitali...@gmail.com> wrote:

Hello
Is it possible to have a text control react on a KeyEvent (created
one, not originated from keyboard), but without giving it focus? Or
if giving a focus is needed than is it possible to restore focus
after?

I am working on a hardware device that lets single computer to have
several keyboards attached to it. Purpose of this is to let several
users to type simultaneously to a single computer but to separate
TextCtrl-s.

I wished to make a small program to experiment with. I made frame with
two text controls and bind the EVT_KEY_DOWN in the one of them with
the method OnKeyDown. In that method I tried to create another
KeyEvent object and to set its attributes according to received event,
and than to send it to another text control using EmulateKeyPress
method. It worked as expected, but it also changed focus to another
text control. So that next key press was directed to the second text
control.

You could try using WriteText instead of emulating the keypress, I

Yes that can be done, although that way keys like delete,
backspace, ... would not work.

I have solved the problem by adding following code after
EmulateKeyPress in OnKeyDown method:

textctrl_2.EmulateKeyPress(e2)
app = wx.GetApp()
while app.Pending():
    app.Dispatch()
textctrl_1.SetFocus()