+ /* If a key is pressed and AltGr is not active */
+ if (key_down && (keystate[VK_RMENU]&0x80) == 0 && !compose_state)
+ {
+ /* Okay, prepare for most alts then ...*/
+ if (left_alt) *p++ = '\033';
+
+ /* Lets see if it's a pattern we know all about ... */
+ if (wParam == VK_PRIOR && shift_state == 1) {
+ SendMessage (hwnd, WM_VSCROLL, SB_PAGEUP, 0);
+ return 0;
+ }
+ if (wParam == VK_NEXT && shift_state == 1) {
+ SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0);
+ return 0;
+ }
+ if (wParam == VK_INSERT && shift_state == 1) {
+ term_mouse (MB_PASTE, MA_CLICK, 0, 0);
+ term_mouse (MB_PASTE, MA_RELEASE, 0, 0);
+ return 0;
+ }
+ if (left_alt && wParam == VK_F4 && cfg.alt_f4) {
+ return -1;
+ }
+ if (left_alt && wParam == VK_SPACE && cfg.alt_space) {
+ PostMessage(hwnd, WM_CHAR, ' ', 0);
+ SendMessage (hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
+ return -1;
+ }
+ /* Control-Numlock for app-keypad mode switch */
+ if (wParam == VK_PAUSE && shift_state == 2) {
+ app_keypad_keys ^= 1;
+ return 0;
+ }
+
+ /* Nethack keypad */
+ if (cfg.nethack_keypad && !left_alt) {
+ switch(wParam) {
+ case VK_NUMPAD1: *p++ = shift_state ? 'B': 'b'; return p-output;
+ case VK_NUMPAD2: *p++ = shift_state ? 'J': 'j'; return p-output;
+ case VK_NUMPAD3: *p++ = shift_state ? 'N': 'n'; return p-output;
+ case VK_NUMPAD4: *p++ = shift_state ? 'H': 'h'; return p-output;
+ case VK_NUMPAD5: *p++ = shift_state ? '.': '.'; return p-output;
+ case VK_NUMPAD6: *p++ = shift_state ? 'L': 'l'; return p-output;
+ case VK_NUMPAD7: *p++ = shift_state ? 'Y': 'y'; return p-output;
+ case VK_NUMPAD8: *p++ = shift_state ? 'K': 'k'; return p-output;
+ case VK_NUMPAD9: *p++ = shift_state ? 'U': 'u'; return p-output;
+ }
+ }
+
+ /* Application Keypad */
+ if (!left_alt) {
+ int xkey = 0;
+
+ if ( cfg.funky_type == 3 ||
+ ( cfg.funky_type <= 1 &&
+ app_keypad_keys && !cfg.no_applic_k)) switch(wParam) {
+ case VK_EXECUTE: xkey = 'P'; break;
+ case VK_DIVIDE: xkey = 'Q'; break;
+ case VK_MULTIPLY:xkey = 'R'; break;
+ case VK_SUBTRACT:xkey = 'S'; break;
+ }
+ if(app_keypad_keys && !cfg.no_applic_k) switch(wParam) {
+ case VK_NUMPAD0: xkey = 'p'; break;
+ case VK_NUMPAD1: xkey = 'q'; break;
+ case VK_NUMPAD2: xkey = 'r'; break;
+ case VK_NUMPAD3: xkey = 's'; break;
+ case VK_NUMPAD4: xkey = 't'; break;
+ case VK_NUMPAD5: xkey = 'u'; break;
+ case VK_NUMPAD6: xkey = 'v'; break;
+ case VK_NUMPAD7: xkey = 'w'; break;
+ case VK_NUMPAD8: xkey = 'x'; break;
+ case VK_NUMPAD9: xkey = 'y'; break;
+
+ case VK_DECIMAL: xkey = 'n'; break;
+ case VK_ADD: if(cfg.funky_type==2) {
+ if(shift_state) xkey = 'l';
+ else xkey = 'k';
+ } else if(shift_state) xkey = 'm';
+ else xkey = 'l';
+ break;
+
+ case VK_DIVIDE: if(cfg.funky_type==2) xkey = 'o'; break;
+ case VK_MULTIPLY:if(cfg.funky_type==2) xkey = 'j'; break;
+ case VK_SUBTRACT:if(cfg.funky_type==2) xkey = 'm'; break;
+
+ case VK_RETURN:
+ if (HIWORD(lParam)&KF_EXTENDED)
+ xkey = 'M';
+ break;
+ }
+ if(xkey)
+ {
+ if (vt52_mode)
+ {
+ if (xkey>='P' && xkey<='S')
+ p += sprintf((char *)p, "\x1B%c", xkey);
+ else
+ p += sprintf((char *)p, "\x1B?%c", xkey);
+ }
+ else
+ p += sprintf((char *)p, "\x1BO%c", xkey);
+ return p - output;
+ }
+ }
+
+ if (wParam == VK_BACK && shift_state == 0 ) /* Backspace */
+ {
+ *p++ = (cfg.bksp_is_delete ? 0x7F : 0x08);
+ return p-output;
+ }
+ if (wParam == VK_TAB && shift_state == 1 ) /* Shift tab */
+ {
+ *p++ = 0x1B; *p++ = '['; *p++ = 'Z'; return p - output;
+ }
+ if (wParam == VK_SPACE && shift_state == 2 ) /* Ctrl-Space */
+ {
+ *p++ = 0; return p - output;