![]() ![]() The code also turns off keyevents (both keyup and keydown) as soon as one of them occurs. But a keyup event will fire (when you finally release the Ctrl-key). If you hold down the Ctrl-key when opening the file then a keydown event will never fire in the javascript code. So I wanted to distinguish between these two options by holding down the Ctrl-key or not, while pressing Enter.Īs you all have understood from all the answers here, this seems to be not really possible, but here is a way that mimics this behaviour in a way that was acceptable for me. I had a need to open a special html file locally (by pressing Enter when the file is selected in the file explorer in Windows), either just for viewing the file or for editing it in a special online editor. I'm sure there's some library out there that abstracts over this DOM weakness, or maybe some DOM standard change took care of it, since it's a rather old question. This, combined with the modifiers is pretty airtight, though I haven't explored what to do with Tab and Backspace. Basically, if keypress doesn't keep firing, then it's possible to rule out most of the keys. ![]() ![]() There's some latency in resetting the key though, due to the periodicity of keypress firing. assuming that there is at least one mouse interaction expected when tabbing back, which is frequently the case.įor most all other keys (except modifiers, Tab, Delete, but including Space, Enter), monitoring keypress would work for most applications - a key held down will continue to fire. Modifier keys ( Shift etc.) can be monitored via mousemove etc. Or some key is simply kept held, while the user is switching to another tab or application with the mouse, then released outside our page. Coming back to the browser page, it'll still think the key is held, though it was released in the meantime. If the user alt-tabs away, or uses a key gesture to open a new browser window or tab, then a keydown will be registered, which is fine, because at that point it's impossible to tell if the key is something the web app is monitoring, or is a standard browser or OS shortcut. I scanned the above answers and the proposed keydown/ keyup approach works only under special circumstances. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |