anko / hudkit

transparent fullscreen on-top click-through WebKit web view, for making cool desktop HUDs
ISC License
104 stars 14 forks source link

Support keyboard input #12

Open anko opened 3 years ago

anko commented 3 years ago

So I finally figured out how to make an override_redirect window get keyboard focus: it has to grab the keyboard device itself. https://github.com/anko/hudkit/commit/d40cb15eea00588c09e9deacc7af6bfa9cd07001 is an initial proof of concept that this works. This draft PR is a dumping ground for thoughts and plans on how to proceed, toward something stable enough to release, as if I ever finished anything worthwhile.

If you check out the grab-keyboard branch and run the example/, the leftmost 100 pixels of column on your leftmost monitor should be a clickable area, and when you hover over it, you can also type text, which the webview can react to as you'd expect by listening to keydown events.

https://user-images.githubusercontent.com/5231746/116835815-66b4d980-abc4-11eb-86fe-8ebf362101ee.mp4

Incidentally, this also makes it possible to type into the Web Inspector also when it is docked to the overlay window.


Bugs to be fixed:

Also have to think about the API design of this. My plan so far is to add Hudkit.grabKeyboard()/.ungrabKeyboard() to the JS API, so user code can grab it when appropriate, instead of always. You might for example want some elements to only be clickable, without grabbing keyboard focus when they are hovered, while others should grab keyboard focus.

The command line flag to control this could look like --grab-keyboard followed by

Haven't decided what the default should be yet.