Skip to content

Commit 9117240

Browse files
Added: Add shift key support in extra keys and terminal with SHIFT or SHFT
Closes #1038
1 parent fbb9114 commit 9117240

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

app/src/main/java/com/termux/app/terminal/TermuxTerminalViewClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ public boolean readAltKey() {
297297
return readExtraKeysSpecialButton(SpecialButton.ALT);
298298
}
299299

300+
@Override
301+
public boolean readShiftKey() {
302+
return readExtraKeysSpecialButton(SpecialButton.SHIFT);
303+
}
304+
300305
public boolean readExtraKeysSpecialButton(SpecialButton specialButton) {
301306
if (mActivity.getExtraKeysView() == null) return false;
302307
Boolean state = mActivity.getExtraKeysView().readSpecialButton(specialButton, true);

terminal-view/src/main/java/com/termux/view/TerminalView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
598598
final int metaState = event.getMetaState();
599599
final boolean controlDown = event.isCtrlPressed() || mClient.readControlKey();
600600
final boolean leftAltDown = (metaState & KeyEvent.META_ALT_LEFT_ON) != 0 || mClient.readAltKey();
601+
final boolean shiftDown = event.isShiftPressed() || mClient.readShiftKey();
601602
final boolean rightAltDownFromEvent = (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;
602603

603604
int keyMod = 0;
604605
if (controlDown) keyMod |= KeyHandler.KEYMOD_CTRL;
605606
if (event.isAltPressed() || leftAltDown) keyMod |= KeyHandler.KEYMOD_ALT;
606-
if (event.isShiftPressed()) keyMod |= KeyHandler.KEYMOD_SHIFT;
607+
if (shiftDown) keyMod |= KeyHandler.KEYMOD_SHIFT;
607608
if (event.isNumLockOn()) keyMod |= KeyHandler.KEYMOD_NUM_LOCK;
608609
if (!event.isFunctionPressed() && handleKeyCode(keyCode, keyMod)) {
609610
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) {
620621
}
621622
int effectiveMetaState = event.getMetaState() & ~bitsToClear;
622623

624+
if (shiftDown) effectiveMetaState |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
625+
623626
int result = event.getUnicodeChar(effectiveMetaState);
624627
if (TERMINAL_VIEW_KEY_LOGGING_ENABLED)
625628
mClient.logInfo(LOG_TAG, "KeyEvent#getUnicodeChar(" + effectiveMetaState + ") returned: " + result);

terminal-view/src/main/java/com/termux/view/TerminalViewClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public interface TerminalViewClient {
5454

5555
boolean readAltKey();
5656

57+
boolean readShiftKey();
58+
59+
5760

5861
boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);
5962

termux-shared/src/main/java/com/termux/shared/terminal/TermuxTerminalViewClientBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public boolean readAltKey() {
6767
return false;
6868
}
6969

70+
public boolean readShiftKey() {
71+
return false;
72+
}
73+
74+
75+
7076
@Override
7177
public boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session) {
7278
return false;

termux-shared/src/main/java/com/termux/shared/terminal/io/extrakeys/ExtraKeysConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public static class EXTRA_KEY_DISPLAY_MAPS {
173173
public static final ExtraKeyDisplayMap CONTROL_CHARS_ALIASES = new ExtraKeyDisplayMap() {{
174174
put("ESCAPE", "ESC");
175175
put("CONTROL", "CTRL");
176+
put("SHFT", "SHIFT");
176177
put("RETURN", "ENTER"); // Technically different keys, but most applications won't see the difference
177178
put("FUNCTION", "FN");
178179
// no alias for ALT

0 commit comments

Comments
 (0)