Kotlin/Wasm and keyboard events

Hi I’ve been trying find any documentation about this but couldn’t find anything, I tried using desktop compose approach, but no luck, I couldn’t move a single square with my keyboard arrows, if anyone out there can give me pointers on how to archive it in kotlin/wasm I appreciate it.

@Composable @Preview fun mainScreen() { var xPosition by remember { mutableStateOf(50f) } Column( modifier = Modifier .fillMaxSize() .background(color = Color.Red) .onPreviewKeyEvent { event: KeyEvent -> if (event.type == KeyEventType.KeyDown) { when (event.key) { Key.DirectionLeft -> { // Left arrow key xPosition -= 10f true } Key.DirectionRight -> { // Right arrow key xPosition += 10f true } else -> false } } else false }, verticalArrangement = Arrangement.Center ) { Box( modifier = Modifier .size(100.dp) ) { Canvas(modifier = Modifier.fillMaxSize()) { drawRect( color = Color.Blue, topLeft = androidx.compose.ui.geometry.Offset(xPosition, 0f), size = androidx.compose.ui.geometry.Size(100f, 100f) ) } } } } 

submitted by /u/olrc
[link] [comments]