forked from extern/Unexpected-Keyboard
Fix modifiers not cleared when presses overlap
When typing fast, a second key might be pressed before the first is released. Clearing modifiers earlier would prevent this but would break modifiers placed in corners (especially the accent keys). Instead, don't take latched modifiers into account when registering the second press. A new flag is needed to not interfere with holding modifers, which is merged with the norepeat flag.
This commit is contained in:
parent
84af72c222
commit
b72635b887
@ -20,7 +20,8 @@ class KeyValue
|
||||
// Behavior flags
|
||||
public static final int FLAG_LATCH = 1;
|
||||
public static final int FLAG_LOCK = (1 << 1);
|
||||
public static final int FLAG_NOREPEAT = (1 << 2);
|
||||
// Special keys are not repeated and don't clear latched modifiers
|
||||
public static final int FLAG_SPECIAL = (1 << 2);
|
||||
public static final int FLAG_NOCHAR = (1 << 3);
|
||||
public static final int FLAG_PRECISE_REPEAT = (1 << 4);
|
||||
|
||||
@ -135,7 +136,7 @@ class KeyValue
|
||||
private static void addModifierKey(String name, String symbol, int extra_flags)
|
||||
{
|
||||
addKey(name, symbol, CHAR_NONE, EVENT_NONE,
|
||||
FLAG_LATCH | FLAG_NOCHAR | FLAG_NOREPEAT | extra_flags);
|
||||
FLAG_LATCH | FLAG_NOCHAR | FLAG_SPECIAL | extra_flags);
|
||||
}
|
||||
|
||||
private static void addSpecialKey(String name, String symbol, int event)
|
||||
@ -145,7 +146,7 @@ class KeyValue
|
||||
|
||||
private static void addSpecialKey(String name, String symbol, int event, int flags)
|
||||
{
|
||||
addKey(name, symbol, CHAR_NONE, event, flags | FLAG_NOREPEAT);
|
||||
addKey(name, symbol, CHAR_NONE, event, flags | FLAG_SPECIAL);
|
||||
}
|
||||
|
||||
private static void addEventKey(String name, String symbol, int event)
|
||||
|
@ -23,10 +23,19 @@ public final class Pointers implements Handler.Callback
|
||||
}
|
||||
|
||||
public int getFlags()
|
||||
{
|
||||
return getFlags(false);
|
||||
}
|
||||
|
||||
/* When [skip_latched] is true, don't take flags of latched keys into account. */
|
||||
private int getFlags(boolean skip_latched)
|
||||
{
|
||||
int flags = 0;
|
||||
for (Pointer p : _ptrs)
|
||||
flags |= p.flags;
|
||||
{
|
||||
if (!(skip_latched && p.pointerId == -1 && (p.flags & KeyValue.FLAG_LOCKED) == 0))
|
||||
flags |= p.flags;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
@ -107,6 +116,15 @@ public final class Pointers implements Handler.Callback
|
||||
_handler.onPointerFlagsChanged();
|
||||
}
|
||||
|
||||
/* Whether an other pointer is down on a non-special key. */
|
||||
private boolean isOtherPointerDown()
|
||||
{
|
||||
for (Pointer p : _ptrs)
|
||||
if (p.pointerId != -1 && (p.flags & KeyValue.FLAG_SPECIAL) == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key)
|
||||
{
|
||||
// Ignore new presses while a modulated key is active. On some devices,
|
||||
@ -114,11 +132,11 @@ public final class Pointers implements Handler.Callback
|
||||
// keys.
|
||||
if (isModulatedKeyPressed())
|
||||
return;
|
||||
int mflags = getFlags();
|
||||
int mflags = getFlags(isOtherPointerDown());
|
||||
KeyValue value = _handler.onPointerDown(key.key0, mflags);
|
||||
Pointer ptr = new Pointer(pointerId, key, 0, value, x, y, mflags);
|
||||
_ptrs.add(ptr);
|
||||
if (value != null && (value.flags & KeyValue.FLAG_NOREPEAT) == 0)
|
||||
if (value != null && (value.flags & KeyValue.FLAG_SPECIAL) == 0)
|
||||
startKeyRepeat(ptr);
|
||||
}
|
||||
|
||||
@ -164,7 +182,7 @@ public final class Pointers implements Handler.Callback
|
||||
if ((old_flags & newValue.flags & KeyValue.FLAG_PRECISE_REPEAT) == 0)
|
||||
{
|
||||
stopKeyRepeat(ptr);
|
||||
if ((newValue.flags & KeyValue.FLAG_NOREPEAT) == 0)
|
||||
if ((newValue.flags & KeyValue.FLAG_SPECIAL) == 0)
|
||||
startKeyRepeat(ptr);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user