changeset 104:171e0a977544

cleanup keystroke handling
author Carl Byington <carl@five-ten-sg.com>
date Wed, 18 Jun 2014 10:10:14 -0700
parents 1a34365fab9b
children 1b5887a3bb1c
files src/com/five_ten_sg/connectbot/transport/TN5250.java src/de/mud/terminal/VDUInput.java src/de/mud/terminal/vt320.java
diffstat 3 files changed, 7 insertions(+), 251 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/transport/TN5250.java	Tue Jun 17 22:01:53 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/TN5250.java	Wed Jun 18 10:10:14 2014 -0700
@@ -139,8 +139,8 @@
 
         // monitor injecting a field
         @Override
-        public void setField(int l, int c, char [] d) {
-            screen52.setField(l, c, d);
+        public void setField(int l, int c, char [] data) {
+            screen52.setField(l, c, data);
         }
 
         // terminal key listener sending to local screen
--- a/src/de/mud/terminal/VDUInput.java	Tue Jun 17 22:01:53 2014 -0700
+++ b/src/de/mud/terminal/VDUInput.java	Wed Jun 18 10:10:14 2014 -0700
@@ -72,19 +72,11 @@
     void setKeyCodes(Properties codes);
 
     /**
-     * main keytyping event handler...
+     * keytyping event handler for all the special function and modifier keys
      * @param keyCode the key code
      * @param keyChar the character represented by the key
      * @param modifiers shift/alt/control modifiers
      */
     void keyPressed(int keyCode, char keyChar, int modifiers);
 
-    /**
-     * Handle key Typed events for the terminal, this will get
-     * all normal key types, but no shift/alt/control/numlock.
-     * @param keyCode the key code
-     * @param keyChar the character represented by the key
-     * @param modifiers shift/alt/control modifiers
-     */
-    void keyTyped(int keyCode, char keyChar, int modifiers);
 }
--- a/src/de/mud/terminal/vt320.java	Tue Jun 17 22:01:53 2014 -0700
+++ b/src/de/mud/terminal/vt320.java	Wed Jun 18 10:10:14 2014 -0700
@@ -944,7 +944,8 @@
     }
 
     /**
-     * main keytyping event handler...
+     * main keytyping event handler for all the special function and modifier keys
+     * the normal keys are processed by write(byte b);
      */
     public void keyPressed(int keyCode, char keyChar, int modifiers) {
         boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0;
@@ -1112,7 +1113,7 @@
                 break;
 
             case KEY_ESCAPE:
-                write(0x1b);
+                writeSpecial(Escape[xind]);
                 break;
 
             case KEY_ENTER:
@@ -1120,250 +1121,13 @@
                 break;
 
             case KEY_TAB:
-                write(0x09);
+                writeSpecial(TabKey[xind]);
                 break;
 
             default:
                 break;
         }
     }
-    /*
-      public void keyReleased(KeyEvent evt) {
-        if (debug > 1) debug("keyReleased("+evt+")");
-        // ignore
-      }
-    */
-    /**
-     * Handle key Typed events for the terminal, this will get
-     * all normal key types, but no shift/alt/control/numlock.
-     */
-    public void keyTyped(int keyCode, char keyChar, int modifiers) {
-        boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0;
-        boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0;
-        boolean alt = (modifiers & VDUInput.KEY_ALT) != 0;
-
-        if (debug > 1) debug("keyTyped(" + keyCode + ", " + (int)keyChar + ", " + modifiers + ")");
-
-        if (keyChar == '\t') {
-            if (shift) {
-                write(TabKey[1], false);
-            }
-            else {
-                if (control) {
-                    write(TabKey[2], false);
-                }
-                else {
-                    if (alt) {
-                        write(TabKey[3], false);
-                    }
-                    else {
-                        write(TabKey[0], false);
-                    }
-                }
-            }
-
-            return;
-        }
-
-        if (alt) {
-            write(((char)(keyChar | 0x80)));
-            return;
-        }
-
-        if (((keyCode == KEY_ENTER) || (keyChar == 10))
-                && !control) {
-            write('\r');
-
-            if (localecho) putString("\r\n");  // bad hack
-
-            return;
-        }
-
-        if ((keyCode == 10) && !control) {
-            debug("Sending \\r");
-            write('\r');
-            return;
-        }
-
-        // FIXME: on german PC keyboards you have to use Alt-Ctrl-q to get an @,
-        // so we can't just use it here... will probably break some other VMS
-        // codes.  -Marcus
-        // if(((!vms && keyChar == '2') || keyChar == '@' || keyChar == ' ')
-        //    && control)
-        if (((!vms && keyChar == '2') || keyChar == ' ') && control)
-            write(0);
-
-        if (vms) {
-            if (keyChar == 127 && !control) {
-                if (shift)
-                    writeSpecial(Insert[0]);        //  VMS shift delete = insert
-                else
-                    writeSpecial(Remove[0]);        //  VMS delete = remove
-
-                return;
-            }
-            else if (control)
-                switch (keyChar) {
-                    case '0':
-                        writeSpecial(Numpad[0]);
-                        return;
-
-                    case '1':
-                        writeSpecial(Numpad[1]);
-                        return;
-
-                    case '2':
-                        writeSpecial(Numpad[2]);
-                        return;
-
-                    case '3':
-                        writeSpecial(Numpad[3]);
-                        return;
-
-                    case '4':
-                        writeSpecial(Numpad[4]);
-                        return;
-
-                    case '5':
-                        writeSpecial(Numpad[5]);
-                        return;
-
-                    case '6':
-                        writeSpecial(Numpad[6]);
-                        return;
-
-                    case '7':
-                        writeSpecial(Numpad[7]);
-                        return;
-
-                    case '8':
-                        writeSpecial(Numpad[8]);
-                        return;
-
-                    case '9':
-                        writeSpecial(Numpad[9]);
-                        return;
-
-                    case '.':
-                        writeSpecial(KPPeriod);
-                        return;
-
-                    case '-':
-                    case 31:
-                        writeSpecial(KPMinus);
-                        return;
-
-                    case '+':
-                        writeSpecial(KPComma);
-                        return;
-
-                    case 10:
-                        writeSpecial(KPEnter);
-                        return;
-
-                    case '/':
-                        writeSpecial(PF2);
-                        return;
-
-                    case '*':
-                        writeSpecial(PF3);
-                        return;
-
-                    /* NUMLOCK handled in keyPressed */
-                    default:
-                        break;
-                }
-
-            /* Now what does this do and how did it get here. -Marcus
-            if (shift && keyChar < 32) {
-              write(PF1+(char)(keyChar + 64));
-              return;
-            }
-            */
-        }
-
-        // FIXME: not used?
-        //String fmap[];
-        int xind;
-        xind = 0;
-
-        //fmap = FunctionKey;
-        if (shift) {
-            //fmap = FunctionKeyShift;
-            xind = 1;
-        }
-
-        if (control) {
-            //fmap = FunctionKeyCtrl;
-            xind = 2;
-        }
-
-        if (alt) {
-            //fmap = FunctionKeyAlt;
-            xind = 3;
-        }
-
-        if (keyCode == KEY_ESCAPE) {
-            writeSpecial(Escape[xind]);
-            return;
-        }
-
-        if ((modifiers & VDUInput.KEY_ACTION) != 0)
-            switch (keyCode) {
-                case KEY_NUMPAD0:
-                    writeSpecial(Numpad[0]);
-                    return;
-
-                case KEY_NUMPAD1:
-                    writeSpecial(Numpad[1]);
-                    return;
-
-                case KEY_NUMPAD2:
-                    writeSpecial(Numpad[2]);
-                    return;
-
-                case KEY_NUMPAD3:
-                    writeSpecial(Numpad[3]);
-                    return;
-
-                case KEY_NUMPAD4:
-                    writeSpecial(Numpad[4]);
-                    return;
-
-                case KEY_NUMPAD5:
-                    writeSpecial(Numpad[5]);
-                    return;
-
-                case KEY_NUMPAD6:
-                    writeSpecial(Numpad[6]);
-                    return;
-
-                case KEY_NUMPAD7:
-                    writeSpecial(Numpad[7]);
-                    return;
-
-                case KEY_NUMPAD8:
-                    writeSpecial(Numpad[8]);
-                    return;
-
-                case KEY_NUMPAD9:
-                    writeSpecial(Numpad[9]);
-                    return;
-
-                case KEY_DECIMAL:
-                    writeSpecial(NUMDot[xind]);
-                    return;
-
-                case KEY_ADD:
-                    writeSpecial(NUMPlus[xind]);
-                    return;
-            }
-
-        if (!((keyChar == 8) || (keyChar == 127) || (keyChar == '\r') || (keyChar == '\n'))) {
-            write(keyChar);
-            return;
-        }
-    }
 
     private void handle_dcs(String dcs) {
         debugStr.append("DCS: ")