keyWentDown signal preventDefaultAction only for functional keys
Added by Alex Ignatov over 6 years ago
Hi, I would like to react to some F keys in my application and prevent default browser action on that keys. If I use preventDefaultAction method on the keyWentDown signal it would also prevent typing into the form input and so on. Is there a way to prevent default action only for specific keys?
Thanks!
Alex
Replies (4)
RE: keyWentDown signal preventDefaultAction only for functional keys - Added by lm at over 6 years ago
Maybe in your signal handler, you should call preventDefaultAction(true)
if you detect a function key (or whatever you're wanting to prevent), and call preventDefaultAction(false)
otherwise?
RE: keyWentDown signal preventDefaultAction only for functional keys - Added by Alex Ignatov over 6 years ago
Neither preventDefaultAction(true) nor preventPropagation(true) has no effect when called from the event handler. I tried calling it on the widget object keyWentDown() signal and also on the Wt::WApplication::instance()->globalKeyWentDown() signal. Both work if called in the widget constructor, but there it applies on any key pressed. And both do not work in the event handler, where I have an event object with the information on which key was pressed.
Any other ideas how to do workaround this? I can of course prevent default action for all keys in the constructor and then handle myself typing into the input fields, but I still hope for an easier solution))
RE: keyWentDown signal preventDefaultAction only for functional keys - Added by lm at over 6 years ago
I thought about capturing all keyboard events and "manually" acting for some of them, but that's terribly onerous. When I press CTRL+A, you're going to select all the text? When the user selects a word and presses "a", you're going to remove the word and replace it with 'a'? I anticipate only confusion and delay down those tracks.
Sorry, I'm out of ideas. On the other hand, you neatly answered my inquiry of earlier: https://redmine.webtoolkit.eu/boards/2/topics/14729
RE: keyWentDown signal preventDefaultAction only for functional keys - Added by Alex Ignatov over 6 years ago
Glad to know this solved your problem. So you will disable browser default action and process all key events manually to respond with b to a? By the way you could post a link to this thread in your topic or just post an answer there ;)