https://kotlinlang.org logo
#compose-android
Title
# compose-android
p

Peter Enyedi

11/15/2023, 11:13 AM
Hi all! I have a custom air mouse that should be able to "communicate" with Android TV. When I click with this mouse, it sends an ENTER key event instead of a click. I'm developing a Compose app for Android TV and the built-in buttons, tabs, etc, don't handle this event. How could I interpret this ENTER event as a click event? Thanks! I have already tried
Copy code
Modifier.onKeyEvent {
   if (it.key == Key.Enter) {
      onClick()
      true
   } else false
}
but doesn't seem to work. 😕
z

Zach Klippenstein (he/him) [MOD]

11/15/2023, 2:05 PM
Please file a feature request, I thought we supported this but maybe TV is doing something different
Wait, how does that code not work? Is compose not even getting the Enter key event?
p

Peter Enyedi

11/15/2023, 2:16 PM
Actually I'm using Compose for TV, so maybe this is why (still in alpha). But yeah, debugger not even stopping at
if
z

Zach Klippenstein (he/him) [MOD]

11/15/2023, 2:17 PM
But you’re seeing the key event in a View?
p

Peter Enyedi

11/15/2023, 2:19 PM
yes. Also I noticed that when a component (tab, button) is in focus, then this ENTER event is handled as a click, without doing any extra, without adding the onKeyEvent modifier.
Should I move the focus to the given component when I hover over with cursor?
z

Zach Klippenstein (he/him) [MOD]

11/15/2023, 2:23 PM
Ah. Key events are only delivered to the focused node. If the node isn’t focused, it won’t get any events. Focusing on hover seems like a reasonable workaround for such an odd device
p

Peter Enyedi

11/15/2023, 2:25 PM
tried with general usb mouse, works the same way, click is interpreted only when component is focused
Any idea how to do focusing on hover?
2 Views