From 91172409610863ec1fb9fd28e4456c3ae42921ee Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Mon, 23 Aug 2021 08:51:30 +0500 Subject: [PATCH] Added: Add shift key support in extra keys and terminal with `SHIFT` or `SHFT` Closes #1038 --- .../com/termux/app/terminal/TermuxTerminalViewClient.java | 5 +++++ .../src/main/java/com/termux/view/TerminalView.java | 5 ++++- .../src/main/java/com/termux/view/TerminalViewClient.java | 3 +++ .../shared/terminal/TermuxTerminalViewClientBase.java | 6 ++++++ .../shared/terminal/io/extrakeys/ExtraKeysConstants.java | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java b/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java index 8e720444bc..329a8633bf 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java @@ -297,6 +297,11 @@ public boolean readAltKey() { return readExtraKeysSpecialButton(SpecialButton.ALT); } + @Override + public boolean readShiftKey() { + return readExtraKeysSpecialButton(SpecialButton.SHIFT); + } + public boolean readExtraKeysSpecialButton(SpecialButton specialButton) { if (mActivity.getExtraKeysView() == null) return false; Boolean state = mActivity.getExtraKeysView().readSpecialButton(specialButton, true); diff --git a/terminal-view/src/main/java/com/termux/view/TerminalView.java b/terminal-view/src/main/java/com/termux/view/TerminalView.java index ef67b1c1e2..198c328bc7 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalView.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalView.java @@ -598,12 +598,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { final int metaState = event.getMetaState(); final boolean controlDown = event.isCtrlPressed() || mClient.readControlKey(); 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; int keyMod = 0; if (controlDown) keyMod |= KeyHandler.KEYMOD_CTRL; 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.isFunctionPressed() && handleKeyCode(keyCode, keyMod)) { if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) mClient.logInfo(LOG_TAG, "handleKeyCode() took key event"); @@ -620,6 +621,8 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { } int effectiveMetaState = event.getMetaState() & ~bitsToClear; + if (shiftDown) effectiveMetaState |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON; + int result = event.getUnicodeChar(effectiveMetaState); if (TERMINAL_VIEW_KEY_LOGGING_ENABLED) mClient.logInfo(LOG_TAG, "KeyEvent#getUnicodeChar(" + effectiveMetaState + ") returned: " + result); diff --git a/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java b/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java index bd60d2d3f6..d68ccbca2a 100644 --- a/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java +++ b/terminal-view/src/main/java/com/termux/view/TerminalViewClient.java @@ -54,6 +54,9 @@ public interface TerminalViewClient { boolean readAltKey(); + boolean readShiftKey(); + + boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session); diff --git a/termux-shared/src/main/java/com/termux/shared/terminal/TermuxTerminalViewClientBase.java b/termux-shared/src/main/java/com/termux/shared/terminal/TermuxTerminalViewClientBase.java index a51ca31b1e..cf3d940c69 100644 --- a/termux-shared/src/main/java/com/termux/shared/terminal/TermuxTerminalViewClientBase.java +++ b/termux-shared/src/main/java/com/termux/shared/terminal/TermuxTerminalViewClientBase.java @@ -67,6 +67,12 @@ public boolean readAltKey() { return false; } + public boolean readShiftKey() { + return false; + } + + + @Override public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session) { return false; diff --git a/termux-shared/src/main/java/com/termux/shared/terminal/io/extrakeys/ExtraKeysConstants.java b/termux-shared/src/main/java/com/termux/shared/terminal/io/extrakeys/ExtraKeysConstants.java index ae678a71cb..f05ea48162 100644 --- a/termux-shared/src/main/java/com/termux/shared/terminal/io/extrakeys/ExtraKeysConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/terminal/io/extrakeys/ExtraKeysConstants.java @@ -173,6 +173,7 @@ public static class EXTRA_KEY_DISPLAY_MAPS { public static final ExtraKeyDisplayMap CONTROL_CHARS_ALIASES = new ExtraKeyDisplayMap() {{ put("ESCAPE", "ESC"); put("CONTROL", "CTRL"); + put("SHFT", "SHIFT"); put("RETURN", "ENTER"); // Technically different keys, but most applications won't see the difference put("FUNCTION", "FN"); // no alias for ALT