How to insert a character from a virtual keyboard into the focused window using Tauri and pure JS?

I’m building a virtual keyboard using Tauri and pure JavaScript. My application is already set up, but I want to insert the character from the virtual keyboard into the focused window when a key is clicked. The issue is that when clicking on a key, the character should only be inserted into the window that currently has focus. However, it seems that the focus might be the issue. Does Tauri or Rust offer a way to handle this focus management?

For reference, the github repo: https://github.com/wilfreud/virtual-keyboard-desktop-test

PS: I have no knowedlge of Rust, but I pick things up pretty quickly and I’m not afraid of googling things if needed. And I’ve been using chatgpt.

  • Temporary copy to clipboard feature

  • using js event.preventDefault()