Status Update
Comments
ig...@jetbrains.com <ig...@jetbrains.com> #2
It also convenient to have active keyboard modifiers, for example, I need it in this CL
One approach is to add this information to PointerInputEvent (
But I think there are cases when we need to know not only about keyboard modifiers. For example, if "W" was pressed when we focus (or open) the window:
- we open a simple game in which "W" means "go forward"
- we press "W"
- we minimize the window and pause the game
- we release "W" (or not)
- we restore the window
- at this moment we need to continue to move if "W" is still pressed, or stop moving
So we need an API for the current state of keyboard/mouse.
For example:
LocalKeyboard.current.isKeyPressed(Key.W)
(can it be observable 🤔?)
But with this API we assume that there is only one keyboard. But we can connect and use two keyboards...
[Deleted User] <[Deleted User]> #3
So we need an API for the current state of keyboard/mouse.
Actually, for your case, you only need to listen for KEY_PRESSED events
I afraid, that implementing such an interface could be tricky at the application level. A window can lose focus and an app stops receiving keyboard events. So it can get KEY_PRESSED but not KEY_RELEASED.
ma...@google.com <ma...@google.com> #4
Thanks folks! Those are really good ideas.
I agree in general that even though the keys functionality is close with pointer input in certain important usecases, binding them together appears wrong to me and not flexible enough.
As for mouse clicks, I think it's possible to introduce it in the pointer event system and it makes a lot of sence of the first glance.
For example: LocalKeyboard.current.isKeyPressed(Key.W)
The idea is observable queries for keys sounds appealing to me, but I didn't spent much time thinking about it.
Let me cc Alex and Ralston who I think should see this. It seems like this bug is essentially two feature requests, so let's split them
ra...@google.com <ra...@google.com> #5
Thanks for adding me to this discussion.
I'll try to explain what happens on Android. When a user persses a key on the keyboard, they will get a "KeyDown" event, and when they release the key they will get a "KeyUp" event. If the user keeps pressing the key, they will get multiple "KeyDown" events (eg typing "eeeeeeeeeeee" by just holding down the "e" key). When they finally release the key, they will get a single "KeyUp" event.
For the game, when the user minimises the screen, or clicks away from that window, the window loses focus, so it will not receive any more KeyEvents. At this point the game should be paused, and the current velocity saved. When the window gains focus again, the game is resumed and the application assumes that the "W" key was released, so the car starts slowing down. If however the W key was still pressed, the application will receive new "KeyDown" events and it can continue accelerating the car.
I want to avoid adding an API that allows the developer to check for the current state of the keyboard. I think only the component in focus should have access to the keyboard state. This gives the end-user control over where keyboard input is sent, and prevents other applications on the screen from listening/querying for keyboard state.
je...@google.com <je...@google.com>
ap...@google.com <ap...@google.com> #6
Branch: androidx-main
commit 3d2e48d5818401ed48067469de79cfe9be07cba3
Author: George Mount <mount@google.com>
Date: Fri Jul 23 15:48:26 2021
Move desktop's button press and keyboard modifier to common
Fixes: 180075467
Desktop compose has added state for button presses and
modifiers. This CL moves that to common API.
RelNote: "PointerEvent now has support for reading
mouse button state and keyboard modifier state."
Test: new tests, new demo
Change-Id: I6310c8e6bd4d2e383389db7d4a33299aa1c52cd3
M compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/example1/Main.jvm.kt
M compose/ui/ui/api/current.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/api/restricted_current.txt
M compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/UiDemos.kt
A compose/ui/ui/integration-tests/ui-demos/src/main/java/androidx/compose/ui/demos/gestures/ButtonMetaStateDemo.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/input/pointer/PointerInputEventProcessorTest.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/input/pointer/PointerEvent.android.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/pointer/PointerEvent.kt
M compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/input/pointer/PointerEvent.desktop.kt
Description
Hello.
There some pointer type specific information that currently isn't available via Pointer API. For example, which mouse button is pressed now. On Desktop we expose AWT raw event object so it's possible to get this info but not for Android.
It also convenient to have active keyboard modifiers, for example, I need it in this CLhttps://android-review.googlesource.com/c/platform/frameworks/support/+/1578803
Both Android and AWT event objects contain this information