bod
11/18/2025, 9:24 PMModifier.onKeyEvent, this seems to work only after the Compose canvas is focused. So I either need to first click on it, or add a bit of JS that finds the canvas and call focus() on it...
Is this a known issue and/or is there a trick?Winson Chiu
11/18/2025, 9:27 PMwindow object. I don't think you can avoid the focus issue, or at least I wasn't able to dig up anything.bod
11/18/2025, 9:28 PMthrough theso in JS?objectwindow
bod
11/18/2025, 9:29 PMkotlinx-browserWinson Chiu
11/18/2025, 9:30 PMbod
11/18/2025, 9:30 PMkotlinx.browser.window , right?bod
11/18/2025, 9:31 PM(document.body!!.shadowRoot!!.querySelectorAll("canvas").item(0) as HTMLElement).focus()Winson Chiu
11/18/2025, 9:33 PMWinson Chiu
11/18/2025, 9:34 PMAlex Styl
11/19/2025, 2:20 AMAlex Styl
11/19/2025, 2:21 AMbod
11/19/2025, 8:16 AMYeah. What are you trying to achieve?I'm making a little game 🙂 So yeah keyboard needs to work obviously.
99.99% of the times you want to use compose's focus system.To be clear, I make my Compose view focused (otherwise
Modifier.onKeyEvent doesn't work). But it's not enough: the canvas itself needs to be focused via javascript (or by clicking on it), otherwise no events are received.
This looks like a bug to be honest. I should report this.