- if (PK_ISEDITING(keysym) && (modifiers & PKM_SHIFT) == 0) {
- int code;
-
- if (term->cfg.funky_type == FUNKY_XTERM) {
- /* Xterm shuffles these keys, apparently. */
- switch (keysym) {
- case PK_HOME: keysym = PK_INSERT; break;
- case PK_INSERT: keysym = PK_HOME; break;
- case PK_DELETE: keysym = PK_END; break;
- case PK_END: keysym = PK_PAGEUP; break;
- case PK_PAGEUP: keysym = PK_DELETE; break;
- case PK_PAGEDOWN: keysym = PK_PAGEDOWN; break;
- default: break; /* else gcc warns `enum value not used' */
- }
- }
-
- /* RXVT Home/End */
- if (term->cfg.rxvt_homeend &&
- (keysym == PK_HOME || keysym == PK_END)) {
- p += sprintf((char *) p, keysym == PK_HOME ? "\x1B[H" : "\x1BOw");
- goto done;
- }
-
- if (term->vt52_mode) {
- int xkey;
-
- /*
- * A real VT52 doesn't have these, and a VT220 doesn't
- * send anything for them in VT52 mode.
- */
- switch (keysym) {
- case PK_HOME: xkey = 'H'; break;
- case PK_INSERT: xkey = 'L'; break;
- case PK_DELETE: xkey = 'M'; break;
- case PK_END: xkey = 'E'; break;
- case PK_PAGEUP: xkey = 'I'; break;
- case PK_PAGEDOWN: xkey = 'G'; break;
- default: xkey=0; break; /* else gcc warns `enum value not used'*/
- }
- p += sprintf((char *) p, "\x1B%c", xkey);
- goto done;
- }
-
- switch (keysym) {
- case PK_HOME: code = 1; break;
- case PK_INSERT: code = 2; break;
- case PK_DELETE: code = 3; break;
- case PK_END: code = 4; break;
- case PK_PAGEUP: code = 5; break;
- case PK_PAGEDOWN: code = 6; break;
- default: code = 0; break; /* else gcc warns `enum value not used' */
- }
- p += sprintf((char *) p, "\x1B[%d~", code);
- goto done;
- }
-
- if (PK_ISFKEY(keysym)) {
- /* Map Shift+F1-F10 to F11-F20 */
- if (keysym >= PK_F1 && keysym <= PK_F10 && (modifiers & PKM_SHIFT))
- keysym += 10;
- if ((term->vt52_mode || term->cfg.funky_type == FUNKY_VT100P) &&
- keysym <= PK_F14) {
- /* XXX This overrides the XTERM/VT52 mode below */
- int offt = 0;
- if (keysym >= PK_F6) offt++;
- if (keysym >= PK_F12) offt++;
- p += sprintf((char *) p, term->vt52_mode ? "\x1B%c" : "\x1BO%c",
- 'P' + keysym - PK_F1 - offt);
- goto done;
- }
- if (term->cfg.funky_type == FUNKY_LINUX && keysym <= PK_F5) {
- p += sprintf((char *) p, "\x1B[[%c", 'A' + keysym - PK_F1);
- goto done;
- }
- if (term->cfg.funky_type == FUNKY_XTERM && keysym <= PK_F4) {
- if (term->vt52_mode)
- p += sprintf((char *) p, "\x1B%c", 'P' + keysym - PK_F1);
- else
- p += sprintf((char *) p, "\x1BO%c", 'P' + keysym - PK_F1);
- goto done;
- }
- p += sprintf((char *) p, "\x1B[%d~", 11 + keysym - PK_F1);
- goto done;
- }
-
- if (PK_ISCURSOR(keysym)) {
- int xkey;
-
- switch (keysym) {
- case PK_UP: xkey = 'A'; break;
- case PK_DOWN: xkey = 'B'; break;
- case PK_RIGHT: xkey = 'C'; break;
- case PK_LEFT: xkey = 'D'; break;
- case PK_REST: xkey = 'G'; break; /* centre key on number pad */
- default: xkey = 0; break; /* else gcc warns `enum value not used' */
- }
- if (term->vt52_mode)
- p += sprintf((char *) p, "\x1B%c", xkey);
- else {
- int app_flg = (term->app_cursor_keys && !term->cfg.no_applic_c);
-
- /* Useful mapping of Ctrl-arrows */
- if (modifiers == PKM_CONTROL)
- app_flg = !app_flg;
-
- if (app_flg)
- p += sprintf((char *) p, "\x1BO%c", xkey);
- else
- p += sprintf((char *) p, "\x1B[%c", xkey);
- }
- goto done;
- }
-
- done:
- if (p > output || tlen > 0) {
- /*
- * Interrupt an ongoing paste. I'm not sure
- * this is sensible, but for the moment it's
- * preferable to having to faff about buffering
- * things.
- */
- term_nopaste(term);
-
- /*
- * We need not bother about stdin backlogs
- * here, because in GUI PuTTY we can't do
- * anything about it anyway; there's no means
- * of asking Windows to hold off on KEYDOWN
- * messages. We _have_ to buffer everything
- * we're sent.
- */
- term_seen_key_event(term);
-
- if (prependesc) {
-#if 0
- fprintf(stderr, "sending ESC\n");
-#endif
- ldisc_send(term->ldisc, "\x1b", 1, 1);
- }
-
- if (p > output) {
-#if 0
- fprintf(stderr, "sending %d bytes:", p - output);
- for (i = 0; i < p - output; i++)
- fprintf(stderr, " %02x", output[i]);
- fprintf(stderr, "\n");
-#endif
- ldisc_send(term->ldisc, output, p - output, 1);
- } else if (tlen > 0) {
-#if 0
- fprintf(stderr, "sending %d unichars:", tlen);
- for (i = 0; i < tlen; i++)
- fprintf(stderr, " %04x", (unsigned) text[i]);
- fprintf(stderr, "\n");
-#endif
- luni_send(term->ldisc, text, tlen, 1);
- }
- }