Skip to content

Commit

Permalink
Added: Add shift key support in extra keys and terminal with SHIFT
Browse files Browse the repository at this point in the history
…or `SHFT`

Closes #1038
  • Loading branch information
agnostic-apollo committed Aug 23, 2021
1 parent fbb9114 commit 9117240
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
Expand Up @@ -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);
Expand Down
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
Expand Up @@ -54,6 +54,9 @@ public interface TerminalViewClient {

boolean readAltKey();

boolean readShiftKey();



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

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 9117240

Please sign in to comment.