Reputation: 81
Fast question:
On a website, there is any way to detect when a keyboard key is pressed while the browser is minimized? or when you have the focus on another window?
For example, you open my website on Chrome, and you switch to Spotify for example, I need to detect if the user press a particular key that he previously binded.
I can imagine that's impossible with javascript because you have no focus on the browser, but, there is any way for it? Making a chrome extension maybe? with Java? Silverlight?
I just need to detect the user pressed the key, nothing else.
Thanks!
EDIT:
My users have already installed a C# app on their computers, can I (maybe) detect the key press in the App and call the browser (which is already opened) in any way?
Upvotes: 5
Views: 3673
Reputation: 1169
This is not possible, although it should be.
The motivation for why it is not possible is perfectly reasonable. There is no doubt that untrusted webpages should not be able to monitor keyboard activity, as this would allow malicious webpages to monitor confidential activity.
However, there are also perfectly legitimate use cases for being able to do this. A good example is a voice communication Web app. It would be useful for such an app to detect when a particular key is pressed, to provide push-to-talk and other keybindings. But this is not currently possible. Indeed, the Discord Web app has to request that users download the desktop version of the app to use push-to-talk effectively.
The reasonable solution would be to allow Web apps to request permission from the user to monitor all or some keyboard activity when out of focus. This is how location, camera, and other sensitive permissions already work. By default, webpages would not have the permission, and so security would be assured for untrusted webpages. This would be an important improvement for the Web as it seeks to expand its relevance to desktop and mobile environments.
Upvotes: 3
Reputation: 193
Basically you want a keylogger... and no, it's not possible, luckily.
Upvotes: -3