My code has an input box that I can focus by pressing "q" on my keyboard, along with several other keyboard shortcuts. This input box also supports inputting text using a microphone in supported browsers.
I'd like to do two things: - Prevent my keyboard shortcuts from firing if any input, textarea, or similar field is focused. - Create a keyboard shortcut (e.keyCode==81 && event.shiftKey) to activate the speech input field so users do not have to click on the mic with their mouse.
It works, but I am getting two problems: 1 - Tested in Chrome and Firefox. Firefox does not work, I get the error: Error: event.srcElement is undefined 2 - If the field is not focused the shortcuts work great (expected). If the field is focused the shortcuts do not work (expected). But if I use the tab key to loose focus of the input field then I can not type in the input field (expected) but they keyboard shortcuts also do not work (unexpected). This was tested in Google Chrome on Windows, (again, Firefox didn't work with that line of code).
1 - Detect to see if event.srcElement is supported, else use event.srcElement if supported, else use an empty string. 2 - I'm an idiot. Hitting tab took me out of my page because there wasn't anything else inside except the input box. I added another element and now it works great.
I have half my question answered, I'm still trying to figure out how I can activate the speech input on the textbox using a keyboard shortcut instead of having the users hit the button with their mouse.