Detecting (lack of) input focus

Hi,

I have an Windows application that is launched from a different program, in a way that for some reason makes Windows decide not to give my program input focus.

So first thing the program puts up a login dialogue, users see it and start typing, but nothing happens.

I tried wx.Dialog.Raise, but it makes no difference.

I’ve made my peace with Windows not giving my program focus, but I’d like to give my users stronger visual feedback to indicate that they can’t start typing just yet, they have to click on the window first. The title
bar has grey text, but that is very easy to overlook. Also, the application icon is blinking, but users aren’t looking at that, they’re looking at the dialogue that just popped up.

Now here’s my problem: I can’t find a test that will tell me if my login dialogue has keyboard focus. Everything I query tells me that it’s active and focused and everything:

Hi,
it is rather difficult to identify the problem without a runnable
sample - in my brief experiments the mentioned function .IsActive()
seems to work as expected - when called on a specific Frame; the same
is true for Raise() - this works if the program itself is activated
within a desktop managment (otherwise the icon of the program in the
taskbar only starts blinking, requiring attention).

I might be possible to mess with activating running apps e.g. via
pywin, e.g. like:

but I am not sure about the compatibility with recent versions of
Python, wxPython, Windows...

I'd probably suggest a rather dirty solution - just imply the missing
focus on first displaying the dialog (even without checking) and show
an appropriare visible instruction "Click here to enter login data..."
- this hint/warning can be removed, once the dialog has been
positively clicked at.

hth,
   vbr

···

2018-10-10 13:33 GMT-22:00, Anders Munch <ajm@flonidan.dk>:

Hi,

I have an Windows application that is launched from a different program, in
a way that for some reason makes Windows decide not to give my program input
focus.
So first thing the program puts up a login dialogue, users see it and start
typing, but nothing happens.

I tried wx.Dialog.Raise, but it makes no difference.

I've made my peace with Windows not giving my program focus, but I'd like to
give my users stronger visual feedback to indicate that they can't start
typing just yet, they have to click on the window first. The title bar has
grey text, but that is very easy to overlook. Also, the application icon is
blinking, but users aren't looking at that, they're looking at the dialogue
that just popped up.

Now here's my problem: I can't find a test that will tell me if my login
dialogue has keyboard focus. Everything I query tells me that it's active
and focused and everything:

- wx.GetApp().IsActive() returns True.

- event.GetActive() for the latest wx.EVT_ACTIVATE event on the
dialogue return True.

- The TextCtrl has received a wx.EVT_SET_FOCUS event with no
wx.EVT_KILL_FOCUS to follow.
And yet, the title bar remains grey.

If I click on the dialogue and click away, both active-flags change to False
just as I would expect, and from then on works fine, but that's a little
late, I need to know the state on startup.

Any ideas? Is there yet another event or state flag I could check?
Perhaps it's a wxWidgets bug, but I hope not, because creating a reproducing
sample won't be easy. When I launch my app from the start menu this doesn't
happen.

Versions: '4.0.3 msw (phoenix) wxWidgets 3.0.5', Python 3.6.6, .exe-built
with cx_Freeze.

regards, Anders

--