2018-06-30 13:31:44

Hi devs,
I am wondering if someone knows the answer to this interesting problem. I am working on one WPF application, which should to capture KeyDown events and react on them.
All works fine, I was surprised when arrow keys worked too with Jaws turned on, because this was a well known problem of many keys capturing mechanisms. But...
They works fine, until I show another dialog from my app, for example messagebox:
MessageBox.Show("This is a simple messagebox.");
After I click ok, focus returns to main form and arrow keys are arriving with a delay of about 2 seconds sometime, what is inacceptable for me.
However when I go to another window and return back, it works normal again.
What do you think can be a cause of this problem? I tried to apply:
Keyboard.Focus(this);
FocusManager.SetFocusedElement(this, this);
To set keyboard and logical focus to the instance of main window (this), but it didn't helped.
Any idea who is responsible for this behavior?

Thanks.

Best regards

Rastislav

2018-06-30 18:07:35

@1, deal with the issue. WPF is the windows presentation foundation. There's not much we can actually do to help you out with it. The only reason I can think of is if you some how screwed up in your code somewhere. We can't really say "who" necessarily is responsible for this problem, but more along the lines of "what". "What" is the problem, then? Most likely JAWS, unfortunately, which has the habit of going slow whenever it wants.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2018-06-30 18:25:48 (edited by Munawar 2018-06-30 18:27:36)

Hi,
Have you tried doing

this.Focus();

?

A problem I've noticed with GUI applications is that sometimes the main window becomes unstable after a message dialog, and this is usually how I solve it.

@Ethin: English might not be OP's native language. Don't forget that this forum is global...

2018-07-01 16:13:03

Hi,
@Ethin:
in Slovak language even in normal speech a personification is often used. Especially in situation like this, there is WPF, Windows Presentation Foundation and Jaws, one from them is causing problems by its behavior. It is very similar to two people, from who one is bad and you need to determine who. So we use person like addressing rather than what.
May be the situation in english language is different, I apologize in that case. Anyway, this figure is useful also because I am possible source of problems too. smile

@Munawar:
I have tried this.Focus() as you adviced, but it didn't helped. However, I have found another interesting solution. I have a menu on the screen, it is only element there. I mean that menu accessible by pressing alt key.
I'we wrote in code after MessageBox.Show():
Keyboard.Focus(mainMenu);
Keyboard.Focus(this);
And surprisingly it works!

My theory is, that Jaws does not catch when MessageBox window is going away so it is still searching for lastly focused element which isn't there. That may be a source of the latency.
WPF seems to have its part on guilt too, because it doesn't fire focus change events after dialog closes, Keyboard.Focus(this) is probably blocked because Focus is already set to this, so events still aren't fired.
I am thinking now about adding some special component, like label, as a stabilization element. It should work theoretically, I must to try it.

Thank you for your answers, now I know, that problem is exactly where I guessed it.

Best regards

Rastislav

2018-07-01 18:06:20

@4, WPF does fire events properly; there are professional apps that use WPF out ther that work fine. Its just JaWS's sucky focus shit.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github