mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Added: Add shift key support in extra keys and terminal with SHIFT
or SHFT
Closes #1038
This commit is contained in:
@@ -297,6 +297,11 @@ public class TermuxTerminalViewClient extends TermuxTerminalViewClientBase {
|
|||||||
return readExtraKeysSpecialButton(SpecialButton.ALT);
|
return readExtraKeysSpecialButton(SpecialButton.ALT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean readShiftKey() {
|
||||||
|
return readExtraKeysSpecialButton(SpecialButton.SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean readExtraKeysSpecialButton(SpecialButton specialButton) {
|
public boolean readExtraKeysSpecialButton(SpecialButton specialButton) {
|
||||||
if (mActivity.getExtraKeysView() == null) return false;
|
if (mActivity.getExtraKeysView() == null) return false;
|
||||||
Boolean state = mActivity.getExtraKeysView().readSpecialButton(specialButton, true);
|
Boolean state = mActivity.getExtraKeysView().readSpecialButton(specialButton, true);
|
||||||
|
@@ -598,12 +598,13 @@ public final class TerminalView extends View {
|
|||||||
final int metaState = event.getMetaState();
|
final int metaState = event.getMetaState();
|
||||||
final boolean controlDown = event.isCtrlPressed() || mClient.readControlKey();
|
final boolean controlDown = event.isCtrlPressed() || mClient.readControlKey();
|
||||||
final boolean leftAltDown = (metaState & KeyEvent.META_ALT_LEFT_ON) != 0 || mClient.readAltKey();
|
final boolean leftAltDown = (metaState & KeyEvent.META_ALT_LEFT_ON) != 0 || mClient.readAltKey();
|
||||||
|
final boolean shiftDown = event.isShiftPressed() || mClient.readShiftKey();
|
||||||
final boolean rightAltDownFromEvent = (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;
|
final boolean rightAltDownFromEvent = (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;
|
||||||
|
|
||||||
int keyMod = 0;
|
int keyMod = 0;
|
||||||
if (controlDown) keyMod |= KeyHandler.KEYMOD_CTRL;
|
if (controlDown) keyMod |= KeyHandler.KEYMOD_CTRL;
|
||||||
if (event.isAltPressed() || leftAltDown) keyMod |= KeyHandler.KEYMOD_ALT;
|
if (event.isAltPressed() || leftAltDown) keyMod |= KeyHandler.KEYMOD_ALT;
|
||||||
if (event.isShiftPressed()) keyMod |= KeyHandler.KEYMOD_SHIFT;
|
if (shiftDown) keyMod |= KeyHandler.KEYMOD_SHIFT;
|
||||||
if (event.isNumLockOn()) keyMod |= KeyHandler.KEYMOD_NUM_LOCK;
|
if (event.isNumLockOn()) keyMod |= KeyHandler.KEYMOD_NUM_LOCK;
|
||||||
if (!event.isFunctionPressed() && handleKeyCode(keyCode, keyMod)) {
|
if (!event.isFunctionPressed() && handleKeyCode(keyCode, keyMod)) {
|
||||||
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) mClient.logInfo(LOG_TAG, "handleKeyCode() took key event");
|
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) mClient.logInfo(LOG_TAG, "handleKeyCode() took key event");
|
||||||
@@ -620,6 +621,8 @@ public final class TerminalView extends View {
|
|||||||
}
|
}
|
||||||
int effectiveMetaState = event.getMetaState() & ~bitsToClear;
|
int effectiveMetaState = event.getMetaState() & ~bitsToClear;
|
||||||
|
|
||||||
|
if (shiftDown) effectiveMetaState |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
|
||||||
|
|
||||||
int result = event.getUnicodeChar(effectiveMetaState);
|
int result = event.getUnicodeChar(effectiveMetaState);
|
||||||
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED)
|
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED)
|
||||||
mClient.logInfo(LOG_TAG, "KeyEvent#getUnicodeChar(" + effectiveMetaState + ") returned: " + result);
|
mClient.logInfo(LOG_TAG, "KeyEvent#getUnicodeChar(" + effectiveMetaState + ") returned: " + result);
|
||||||
|
@@ -54,6 +54,9 @@ public interface TerminalViewClient {
|
|||||||
|
|
||||||
boolean readAltKey();
|
boolean readAltKey();
|
||||||
|
|
||||||
|
boolean readShiftKey();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);
|
boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);
|
||||||
|
|
||||||
|
@@ -67,6 +67,12 @@ public class TermuxTerminalViewClientBase implements TerminalViewClient {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean readShiftKey() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session) {
|
public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session) {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -173,6 +173,7 @@ public class ExtraKeysConstants {
|
|||||||
public static final ExtraKeyDisplayMap CONTROL_CHARS_ALIASES = new ExtraKeyDisplayMap() {{
|
public static final ExtraKeyDisplayMap CONTROL_CHARS_ALIASES = new ExtraKeyDisplayMap() {{
|
||||||
put("ESCAPE", "ESC");
|
put("ESCAPE", "ESC");
|
||||||
put("CONTROL", "CTRL");
|
put("CONTROL", "CTRL");
|
||||||
|
put("SHFT", "SHIFT");
|
||||||
put("RETURN", "ENTER"); // Technically different keys, but most applications won't see the difference
|
put("RETURN", "ENTER"); // Technically different keys, but most applications won't see the difference
|
||||||
put("FUNCTION", "FN");
|
put("FUNCTION", "FN");
|
||||||
// no alias for ALT
|
// no alias for ALT
|
||||||
|
Reference in New Issue
Block a user