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.
This commit is contained in:
Jules Aguillon 2022-03-17 11:24:33 +01:00
parent 2eb615dbf6
commit fe35d5fd5a

View File

@ -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]. */