From fe35d5fd5a96d995e0ff434718b7b2b8bcac5ba5 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 17 Mar 2022 11:24:33 +0100 Subject: Avoid ghost touches while holding modulated keys On some devices, bogus touch events can be sent while holding a key. With modulated keys, it can happens on top of other keys. Ignore every new pointers when a modulated key is pressed. --- srcs/juloo.keyboard2/Pointers.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java index e6db206..1f0e44c 100644 --- a/srcs/juloo.keyboard2/Pointers.java +++ b/srcs/juloo.keyboard2/Pointers.java @@ -107,6 +107,11 @@ public final class Pointers implements Handler.Callback public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key) { + // Ignore new presses while a modulated key is active. On some devices, + // ghost touch events can happen while the pointer travels on top of other + // keys. + if (isModulatedKeyPressed()) + return; KeyValue value = key.key0; Pointer ptr = new Pointer(pointerId, key, value, x, y); _ptrs.add(ptr); @@ -199,6 +204,16 @@ public final class Pointers implements Handler.Callback } } + private boolean isModulatedKeyPressed() + { + for (Pointer ptr : _ptrs) + { + if ((ptr.flags & KeyValue.FLAG_PRECISE_REPEAT) != 0) + return true; + } + return false; + } + // Key repeat /** Message from [_keyrepeat_handler]. */ -- cgit v1.2.3