Hello all,
I have an app that’s exhibiting some strange Focus/Accelerator problems.
The attached code demonstrates the problems.
Workarounds or updates appreciated 🙂
Thanks!
David Muse
Excellent! That javascript worked for me too. Thanks!
Hi David,
I can reproduce but unfortunately it appears to be a bug in Firefox. The problem is not the focus, that is set correctly. Somehow after the print dialog is displayed once, FF appears to re-registers its internal handler or something like that and it handles ctrl-P before our handlers. It’s a really weird thing it does.
The only way I found to make FF behave correctly is to register the keydown event handler very early (too early for wisej) directly in Default.html. Add the script below in Document.html and FF will start acting as it should.
<body>
<script>
document.documentElement.addEventListener(“keydown”, function (e) {
if (e.ctrlKey) {
switch (e.keyCode) {
case 80: // Ctrl-P
e.preventDefault();
break;
}
}
})
</script>
</body>
Ok, I found something that I can reproduce. Maybe it’s related (I.e. fixing it will fix the other problems too).
I believe that clicking on the form, or dragging it, should set focus to the form, and the Accelerator handler should handle ctrl-P. Correct?
I wonder if some variation of occurs, sometimes, at program startup – somehow the browser background gets focus, and then the form can never get focus.
Aaarghhh… There is definitely a race condition, or something 🙂
I tested problems 1 and 3 with Firefox 52.0.2 and consistently got the print dialog instead of my ctrl-P handler. So, I installed some screen cast software and tried to get a screencast of the error. Then, it worked correctly every time. I thought maybe the screencast software was making the computer run slowly, and somehow that was helping, so I exited the screencast software, and it began to fail again. Then, I tried to capture it with my phone, and it started working correctly again. It’s like it knows when I want it to fail 🙂 Now, it works consistently. I can’t make it fail.
I don’t know what conditions are necessary to reproduce these errors, but they definitely occur. I just wish I could prove it.
My guess would be that sometimes the code that sets focus to the main form runs before the form fully exists, so the form doesn’t get focus. But, of course, that’s just a guess.
I’ll keep trying…
Thank you for the test case. This is what I found:
See screen cast of the test using your sample:
https://www.screencast.com/t/K68GplaFlK
Please login first to submit.