-1

So, I have this virtual keyboard...

It's inside a dll, and based on a StayOnTop Modal form. It's called by a function, that returns a WideString with the typed text. This virtual keyboard has it's own TEdit where the user writes and see's what he's writing.

The required behavior is for they KB form to stay on top, and with focus, until the Esc or Enter keys are pressed.

One of the calls to this keyboard happens within the OnShow event of the main form, so it is not visible by the time the keyboard is called the first time.

This always happened until now.

I created a splash form to guide the user through the various steps that are happening until the moment the main form actually loads: Skin loading, plugin loading, db initializing, etc.

The splash screen shows up as soon as the DataModule OnCreate is executed, and is closed on the OnActivate of the main form. So this splash form is not StayOnTop - It doesn't need to be, as it is to close right in the moment the main form shows up.

Somewhere in the middle, the keyboard shows up, so the user can input some required data.

By my account, the keyboard should grab the focus, as it is a modal window, but truth is, the splash form has the focus until I click on the keyboard form, which is what I want to avoid.

If the splash form is called prior to the keyboard, no Modal, no StayOnTop, can someone tell me why it keeps in focus, and how to avoid it if possible.

PS: I did find other questions in SO regarding similar problems, but turns out to be the opposite: Wanting the StayOnTop form to loose focus to the main one. That's not what I need.

nunopicado
  • 307
  • 4
  • 17
  • 1
    Call SetForegroundWindow in OnShow of the keyboard window. – Sertac Akyuz Mar 02 '14 at 02:54
  • 1
    What is the popup parent of the keyboard form? – David Heffernan Mar 02 '14 at 09:20
  • @SertacAkyuz: I just did, but no change... Focus still goes to the splash form in the background – nunopicado Mar 02 '14 at 11:44
  • @DavidHeffernan: I guess it would be none, right now. The keyboard form is created on the dll by the ShowKeyboard function, and I pass nil as the parent component. Is there a better/most correct way to call it? – nunopicado Mar 02 '14 at 11:46
  • 1
    Which form do you wish to be the popup parent? And why is this in a DLL? – David Heffernan Mar 02 '14 at 11:57
  • They keyboard is in a dll because it is to be called by all the modules, from the main app the the plugins! Made sense to do it. As for the parent, I guess it should be whichever form that calls the keyboard, in this case, the main form, since that's the one where the call is made, even though in this particular call's case, the main form is not visible yet. – nunopicado Mar 02 '14 at 12:15
  • 1
    @nuno - Ok. I don't think I can really guess what's happening without a test case.. – Sertac Akyuz Mar 02 '14 at 13:34

1 Answers1

0

Well, I solved my problem. And a simple one it was...

I just added Application.ProcessMessages right before calling the keyboard.

The focus now goes to the keyboard for as long as it is visible.

nunopicado
  • 307
  • 4
  • 17
  • That doesn't really sound like the solution. – David Heffernan Mar 02 '14 at 17:31
  • I agree I don't know the real reason why... I figure some pending message was giving focus to the splash form after the keyboard form was created, and the the ProcessMessages force it to be dealt with before. But I don't really know what message could be doing it... – nunopicado Mar 02 '14 at 18:51