Bluetooth keyboards

41 views
Skip to first unread message

Eric Knudstrup

unread,
Jul 24, 2013, 1:58:34 PM7/24/13
to connectb...@googlegroups.com
I have a Bluetooth keyboard and Connectbot wasn't accepting the control key.  I have made a patch which seems to work in my system, using FLAG_SOFT_KEYBOARD.
I was thinking of submitting it to you, but I was wondering if it might be better to change the TerminalKeyListener class to check if event came from the soft keyboard instead of the hardKeyboard check?
It would seem that then a physical keyboard and the onscreen soft keyboard could be used together and independently.
---- a/src/org/connectbot/service/TerminalKeyListener.java
+++ b/src/org/connectbot/service/TerminalKeyListener.java
@@ -219,11 +219,13 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
                                        metaState &= ~META_CTRL_ON;
                                        bridge.redraw();

-                                       // If there is no hard keyboard or there is a hard keyboard currently hidden,
-                                       // CTRL-1 through CTRL-9 will send F1 through F9
-                                       if ((!hardKeyboard || (hardKeyboard && hardKeyboardHidden))
-                                                       && sendFunctionKey(keyCode))
-                                               return true;
+                                       if(event.FLAG_SOFT_KEYBOARD != 0) {
+                                               // If there is no hard keyboard or there is a hard keyboard currently hidden,
+                                               // CTRL-1 through CTRL-9 will send F1 through F9
+                                               if ((!hardKeyboard || (hardKeyboard && hardKeyboardHidden))
+                                                               && sendFunctionKey(keyCode))
+                                                       return true;
+                                       }

                                        uchar = keyAsControl(uchar);
                                }

Eric Knudstrup

unread,
Jul 26, 2013, 2:45:29 AM7/26/13
to connectb...@googlegroups.com
I was experimenting today trying to make ConnectBot work correctly with my K810 bluetooth keyboard.  With this diff I am able to use the soft keyboard and my K810 concurrently.  The control key does the right thing on my K810 and so does the "Ctrl" button while using the soft keyboard.

--- a/src/org/connectbot/service/TerminalKeyListener.java
+++ b/src/org/connectbot/service/TerminalKeyListener.java
@@ -70,7 +70,6 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
        private final VDUBuffer buffer;
 
        private String keymode = null;
-       private boolean hardKeyboard = false;
 
        private int metaState = 0;
 
@@ -100,9 +99,6 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
                prefs = PreferenceManager.getDefaultSharedPreferences(manager);
                prefs.registerOnSharedPreferenceChangeListener(this);
 
-               hardKeyboard = (manager.res.getConfiguration().keyboard
-                               == Configuration.KEYBOARD_QWERTY);
-
                updateKeymode();
        }
 
@@ -112,13 +108,12 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
         */
        public boolean onKey(View v, int keyCode, KeyEvent event) {
                try {
-                       final boolean hardKeyboardHidden = manager.hardKeyboardHidden;
-
                        // Ignore all key-up events except for the special keys
                        if (event.getAction() == KeyEvent.ACTION_UP) {
                                // There's nothing here for virtual keyboard users.
-                               if (!hardKeyboard || (hardKeyboard && hardKeyboardHidden))
-                                       return false;
+                           if(event.FLAG_SOFT_KEYBOARD != 0) {
+                               return false;
+                           }
 
                                // skip keys if we aren't connected yet or have been disconnected
                                if (bridge.isDisconnected() || bridge.transport == null)
@@ -189,7 +184,7 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
                        int uchar = event.getUnicodeChar(curMetaState);
                        // no hard keyboard?  ALT-k should pass through to below
                        if ((orgMetaState & KeyEvent.META_ALT_ON) != 0 &&
-                                       (!hardKeyboard || hardKeyboardHidden)) {
+                           event.FLAG_SOFT_KEYBOARD != 0) {
                                uchar = 0;
                        }
 
@@ -216,23 +211,24 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
                                }
 
                                if ((metaState & META_CTRL_MASK) != 0) {
+
                                        metaState &= ~META_CTRL_ON;
                                        bridge.redraw();
 
                                        // If there is no hard keyboard or there is a hard keyboard currently hidden,
                                        // CTRL-1 through CTRL-9 will send F1 through F9
-                                       if ((!hardKeyboard || (hardKeyboard && hardKeyboardHidden))
-                                                       && sendFunctionKey(keyCode))
-                                               return true;
-
+                                       if (event.FLAG_SOFT_KEYBOARD != 0 && 
+                                           sendFunctionKey(keyCode)) {
+                                           return true;
+                                       }
                                        uchar = keyAsControl(uchar);
                                }
 
                                // handle pressing f-keys
-                               if ((hardKeyboard && !hardKeyboardHidden)
-                                               && (curMetaState & KeyEvent.META_SHIFT_ON) != 0
-                                               && sendFunctionKey(keyCode))
-                                       return true;
+                               if (event.FLAG_SOFT_KEYBOARD == 0
+                                   && (curMetaState & KeyEvent.META_SHIFT_ON) != 0
+                                   && sendFunctionKey(keyCode))
+                                   return true;
 
                                if (uchar < 0x80)
                                        bridge.transport.write(uchar);
@@ -245,7 +241,7 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
                        }
 
                        // send ctrl and meta-keys as appropriate
-                       if (!hardKeyboard || hardKeyboardHidden) {
+                       if (event.FLAG_SOFT_KEYBOARD != 0) {
                                int k = event.getUnicodeChar(0);
                                int k0 = k;
                                boolean sendCtrl = false;
@@ -269,8 +265,8 @@ public class TerminalKeyListener implements OnKeyListener, OnSharedPreferenceCha
                                }
                        }
                        // try handling keymode shortcuts
-                       if (hardKeyboard && !hardKeyboardHidden &&
-                                       event.getRepeatCount() == 0) {
+                       if (event.FLAG_SOFT_KEYBOARD == 0 &&
+                           event.getRepeatCount() == 0) {
                                if (PreferenceConstants.KEYMODE_RIGHT.equals(keymode)) {
                                        switch (keyCode) {
                                        case KeyEvent.KEYCODE_ALT_RIGHT:
e
Reply all
Reply to author
Forward
0 new messages