Hello, I have a question concerning Compose Deskto...
# compose-desktop
c
Hello, I have a question concerning Compose Desktop. Is it possible to receive global keyboard events for a whole window (like for a simple game)? I found no way to actually receive the events, neither with
.onKeyEvent
, nor with
.shortcuts
. Thank you very much
k
I'd be interested in this as well. I have the whole screen wrapped in a Box which has onKeyEvent modifier. It doesn't receive events until I press arrow keys, then it starts working. And if I click with mouse somewhere on the screen, the key events stop until I press some arrow key again. I'm not sure why.
👍 2
c
I probably found a solution, it seems to be possible to somehow get the local window, the following code solved my problem for now:
Copy code
LocalAppWindow.current.keyboard.apply {
    setShortcut(Key.W) { snake.onDirection(DirectionKey.UP) }
    setShortcut(Key.A) { snake.onDirection(DirectionKey.LEFT) }
    setShortcut(Key.S) { snake.onDirection(DirectionKey.DOWN) }
    setShortcut(Key.D) { snake.onDirection(DirectionKey.RIGHT) }
}
Its just possible to access the window keyboard with LocalAppWindow.current.keyboard