changeset 156:4e1e1a6ee9f9

allow button shortcuts to see key up/down, so the monitor key can toggle properly
author Carl Byington <carl@five-ten-sg.com>
date Mon, 23 Jun 2014 18:23:34 -0700
parents 156b53fc4815
children 269de016813d
files src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java
diffstat 1 files changed, 54 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java	Mon Jun 23 17:54:39 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java	Mon Jun 23 18:23:34 2014 -0700
@@ -145,9 +145,12 @@
             // skip keys if we aren't connected yet or have been disconnected
             if (bridge.isDisconnected()) return false;
 
+            // short cuts can see repeat counts and key up/down
+            if handleShortcuts(v, event, repeat, (event.getAction() == KeyEvent.ACTION_DOWN) return true;
+
             // Ignore all key-up events except for the special keys
             if (event.getAction() == KeyEvent.ACTION_UP) {
-                // There's nothing here for virtual keyboard users.
+                // There's nothing else here for virtual keyboard users.
                 if (!hardKeyboard || hardKeyboardHidden) return false;
 
                 // if keycode debugging enabled, log and print the pressed key
@@ -459,41 +462,6 @@
                     bridge.tryKeyVibrate();
                     return true;
 
-                case KeyEvent.KEYCODE_CAMERA:
-                    // check to see which shortcut the camera button triggers
-                    String hwbuttonShortcut = manager.prefs.getString(
-                                                  PreferenceConstants.CAMERA,
-                                                  PreferenceConstants.HWBUTTON_SCREEN_CAPTURE);
-                    return (handleShortcut(v, hwbuttonShortcut, repeat));
-
-                case KeyEvent.KEYCODE_VOLUME_UP:
-                    // check to see which shortcut the volume button triggers
-                    hwbuttonShortcut = manager.prefs.getString(
-                                           PreferenceConstants.VOLUP,
-                                           PreferenceConstants.HWBUTTON_CTRL);
-                    return (handleShortcut(v, hwbuttonShortcut, repeat));
-
-                case KeyEvent.KEYCODE_VOLUME_DOWN:
-                    // check to see which shortcut the camera button triggers
-                    hwbuttonShortcut = manager.prefs.getString(
-                                           PreferenceConstants.VOLDN,
-                                           PreferenceConstants.HWBUTTON_TAB);
-                    return (handleShortcut(v, hwbuttonShortcut, repeat));
-
-                case KeyEvent.KEYCODE_SEARCH:
-                    // check to see which shortcut the search button triggers
-                    hwbuttonShortcut = manager.prefs.getString(
-                                           PreferenceConstants.SEARCH,
-                                           PreferenceConstants.HWBUTTON_ESC);
-                    return (handleShortcut(v, hwbuttonShortcut, repeat));
-
-                case KeyEvent.KEYCODE_BUTTON_L2:
-                    // check to see which shortcut the ptt button triggers
-                    hwbuttonShortcut = manager.prefs.getString(
-                                           PreferenceConstants.PTT,
-                                           PreferenceConstants.HWBUTTON_MONITOR);
-                    return (handleShortcut(v, hwbuttonShortcut, repeat));
-
                 case KeyEvent.KEYCODE_DEL:
                     if ((metaState & META_ALT_MASK) != 0) {
                         buffer.keyPressed(vt320.KEY_INSERT, ' ', getStateForBuffer());
@@ -599,34 +567,82 @@
         return false;
     }
 
-    private boolean handleShortcut(View v, String shortcut, int repeat) {
+    private boolean handleShortcuts(View v, int keyCode, KeyEvent event, int repeat, boolean down) {
+        switch (keyCode) {
+            case KeyEvent.KEYCODE_CAMERA:
+                // check to see which shortcut the camera button triggers
+                String hwbuttonShortcut = manager.prefs.getString(
+                                              PreferenceConstants.CAMERA,
+                                              PreferenceConstants.HWBUTTON_SCREEN_CAPTURE);
+                return (handleShortcut(v, hwbuttonShortcut, repeat, down));
+
+            case KeyEvent.KEYCODE_VOLUME_UP:
+                // check to see which shortcut the volume button triggers
+                hwbuttonShortcut = manager.prefs.getString(
+                                       PreferenceConstants.VOLUP,
+                                       PreferenceConstants.HWBUTTON_CTRL);
+                return (handleShortcut(v, hwbuttonShortcut, repeat, down));
+
+            case KeyEvent.KEYCODE_VOLUME_DOWN:
+                // check to see which shortcut the camera button triggers
+                hwbuttonShortcut = manager.prefs.getString(
+                                       PreferenceConstants.VOLDN,
+                                       PreferenceConstants.HWBUTTON_TAB);
+                return (handleShortcut(v, hwbuttonShortcut, repeat, down));
+
+            case KeyEvent.KEYCODE_SEARCH:
+                // check to see which shortcut the search button triggers
+                hwbuttonShortcut = manager.prefs.getString(
+                                       PreferenceConstants.SEARCH,
+                                       PreferenceConstants.HWBUTTON_ESC);
+                return (handleShortcut(v, hwbuttonShortcut, repeat, down));
+
+            case KeyEvent.KEYCODE_BUTTON_L2:
+                // check to see which shortcut the ptt button triggers
+                hwbuttonShortcut = manager.prefs.getString(
+                                       PreferenceConstants.PTT,
+                                       PreferenceConstants.HWBUTTON_MONITOR);
+                return (handleShortcut(v, hwbuttonShortcut, repeat, down));
+
+            default: return false;
+        }
+    }
+
+    private boolean handleShortcut(View v, String shortcut, int repeat, boolean down) {
         if (PreferenceConstants.HWBUTTON_SCREEN_CAPTURE.equals(shortcut)) {
             if (repeat > 0) return false;
+            if (!down) return false;
             bridge.captureScreen();
         }
         else if (PreferenceConstants.HWBUTTON_MONITOR.equals(shortcut)) {
             if (repeat > 0) return false;
-            buffer.monitorKey(true);    // key down
+            buffer.monitorKey(down);
         }
         else if (PreferenceConstants.HWBUTTON_CTRL.equals(shortcut)) {
+            if (!down) return false;
             showMetakeyToast(v, PreferenceConstants.HWBUTTON_CTRL);
             metaPress(META_CTRL_ON);
         }
         else if (PreferenceConstants.HWBUTTON_TAB.equals(shortcut)) {
+            if (!down) return false;
             buffer.keyPressed(vt320.KEY_TAB, ' ',  getStateForBuffer());
         }
         else if (PreferenceConstants.HWBUTTON_CTRLA_SPACE.equals(shortcut)) {
+            if (!down) return false;
             buffer.write(0x01);
             buffer.write(' ');
         }
         else if (PreferenceConstants.HWBUTTON_CTRLA.equals(shortcut)) {
+            if (!down) return false;
             buffer.write(0x01);
         }
         else if (PreferenceConstants.HWBUTTON_ESC.equals(shortcut)) {
+            if (!down) return false;
             showMetakeyToast(v, PreferenceConstants.HWBUTTON_ESC);
             sendEscape();
         }
         else if (PreferenceConstants.HWBUTTON_ESC_A.equals(shortcut)) {
+            if (!down) return false;
             sendEscape();
             buffer.write('a');
         }