Created
September 23, 2011 00:21
-
-
Save piscisaureus/1236439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const char* get_vt100_key_base(DWORD code, char shift, char ctrl, | |
size_t* len) { | |
#define VK_CASE(vk, normal_str, shift_str, ctrl_str, shift_ctrl_str) \ | |
case (vk): \ | |
if (shift && ctrl) { \ | |
*len = sizeof shift_ctrl_str; \ | |
return "\033" shift_ctrl_str; \ | |
} else if (shift) { \ | |
*len = sizeof shift_str ; \ | |
return "\033" shift_str; \ | |
} else if (ctrl) { \ | |
*len = sizeof ctrl_str; \ | |
return "\033" ctrl_str; \ | |
} else { \ | |
*len = sizeof normal_str; \ | |
return "\033" normal_str; \ | |
} | |
switch (code) { | |
/* These mappings are the same as Cygwin's. Unmodified and alt-modified */ | |
/* keypad keys comply with linux console, modifiers comply with xterm */ | |
/* modifier usage. F1..f12 and shift-f1..f10 comply with linux console, */ | |
/* f6..f12 with and without modifiers comply with rxvt. */ | |
VK_CASE(VK_NUMPAD5, "[G", "[1;2G", "[1;5G", "[1;6G") | |
VK_CASE(VK_CLEAR, "[G", "[1;2G", "[1;5G", "[1;6G") | |
VK_CASE(VK_LEFT, "[D", "[1;2D", "[1;5D", "[1;6D") | |
VK_CASE(VK_RIGHT, "[C", "[1;2C", "[1;5C", "[1;6C") | |
VK_CASE(VK_UP, "[A", "[1;2A", "[1;5A", "[1;6A") | |
VK_CASE(VK_DOWN, "[B", "[1;2B", "[1;5B", "[1;6B") | |
VK_CASE(VK_PRIOR, "[5~", "[5;2~", "[5;5~", "[5;6~") | |
VK_CASE(VK_NEXT, "[6~", "[6;2~", "[6;5~", "[6;6~") | |
VK_CASE(VK_HOME, "[1~", "[1;2~", "[1;5~", "[1;6~") | |
VK_CASE(VK_END, "[4~", "[4;2~", "[4;5~", "[4;6~") | |
VK_CASE(VK_INSERT, "[2~", "[2;2~", "[2;5~", "[2;6~") | |
VK_CASE(VK_DELETE, "[3~", "[3;2~", "[3;5~", "[3;6~") | |
VK_CASE(VK_F1, "[[A", "[23~", "[11^", "[23^" ) | |
VK_CASE(VK_F2, "[[B", "[24~", "[12^", "[24^" ) | |
VK_CASE(VK_F3, "[[C", "[25~", "[13^", "[25^" ) | |
VK_CASE(VK_F4, "[[D", "[26~", "[14^", "[26^" ) | |
VK_CASE(VK_F5, "[[E", "[28~", "[15^", "[28^" ) | |
VK_CASE(VK_F6, "[17~", "[29~", "[17^", "[29^" ) | |
VK_CASE(VK_F7, "[18~", "[31~", "[18^", "[31^" ) | |
VK_CASE(VK_F8, "[19~", "[32~", "[19^", "[32^" ) | |
VK_CASE(VK_F9, "[20~", "[33~", "[20^", "[33^" ) | |
VK_CASE(VK_F10, "[21~", "[34~", "[21^", "[34^" ) | |
VK_CASE(VK_F11, "[23~", "[23$", "[23^", "[23@" ) | |
VK_CASE(VK_F12, "[24~", "[24$", "[24^", "[24@" ) | |
default: | |
*len = 0; | |
return NULL; | |
} | |
#undef VK_CASE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment