From RDB: a patch to allow special keys (^C, ^Z, Delete, Return) to
[u/mdw/putty] / window.c
index 3618d14..48ba35b 100644 (file)
--- a/window.c
+++ b/window.c
@@ -476,6 +476,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            sprintf(msg, "%s - PuTTY", realhost);
            title = msg;
        }
+       sfree(realhost);
        set_title(title);
        set_icon(title);
     }
@@ -2553,7 +2554,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
 
        if (wParam == VK_BACK && shift_state == 0) {    /* Backspace */
            *p++ = (cfg.bksp_is_delete ? 0x7F : 0x08);
-           return p - output;
+           *p++ = 0;
+           return -2;
        }
        if (wParam == VK_TAB && shift_state == 1) {     /* Shift tab */
            *p++ = 0x1B;
@@ -2571,7 +2573,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
        }
        if (wParam == VK_CANCEL && shift_state == 2) {  /* Ctrl-Break */
            *p++ = 3;
-           return p - output;
+           *p++ = 0;
+           return -2;
        }
        if (wParam == VK_PAUSE) {      /* Break/Pause */
            *p++ = 26;
@@ -2759,10 +2762,22 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
            if (xkey) {
                if (vt52_mode)
                    p += sprintf((char *) p, "\x1B%c", xkey);
-               else if (app_cursor_keys && !cfg.no_applic_c)
-                   p += sprintf((char *) p, "\x1BO%c", xkey);
-               else
-                   p += sprintf((char *) p, "\x1B[%c", xkey);
+               else {
+                   int app_flg = (app_cursor_keys && !cfg.no_applic_c);
+                   /* VT100 & VT102 manuals both state the app cursor keys
+                    * only work if the app keypad is on.
+                    */
+                   if (!app_keypad_keys)
+                       app_flg = 0;
+                   /* Useful mapping of Ctrl-arrows */
+                   if (shift_state == 2)
+                       app_flg = !app_flg;
+
+                   if (app_flg)
+                       p += sprintf((char *) p, "\x1BO%c", xkey);
+                   else
+                       p += sprintf((char *) p, "\x1B[%c", xkey);
+               }
                return p - output;
            }
        }
@@ -2773,7 +2788,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
         */
        if (wParam == VK_RETURN) {     /* Return */
            *p++ = 0x0D;
-           return p - output;
+           *p++ = 0;
+           return -2;
        }
     }