How do I get the key name, i.e. <leftmouse> from the 3 byte keycode returned by getchar()?
strtrans() doesn't seem to deal with these. ^Qkey does this, but I was looking for a functional method. Let me know if I've missed something, otherwise please consider the following patch to make strtrans() return <keyname> strings in the place of 3 byte termcap key codes. --- charset.c 2006-05-08 01:00:43.941375000 -0600 +++ charset.c.new 2006-05-08 01:02:19.753875000 -0600 @@ -328,6 +328,7 @@ { char_u *res; char_u *p; + int res_added = 0; #ifdef FEAT_MBYTE int l, len, c; char_u hexbuf[11]; @@ -386,7 +387,40 @@ } else #endif - STRCAT(res, transchar_byte(*p++)); + { + if ( *p == K_SPECIAL ) + { + union { + char_u str[3]; + int c; + } key; + char_u *key_name; + int modifiers = 0; + + key.c = TERMCAP2KEY( *(p+1), *(p+2) ); + + extract_modifiers( key.c, &modifiers ); + key_name = get_special_key_name( key.c, modifiers); + + if ( STRCMP( key_name, "<>" ) && STRCMP( key_name, "" ) + && STRCMP( key_name, "<\\200>") ) + { + char_u res1; + + p += 3; + res_added += STRLEN( key_name ); + // vim_realloc does a free() + res = realloc( res, + (unsigned)(vim_strsize(s) + 1) + res_added ); + STRCAT( res, key_name ); + } + else + STRCAT(res, transchar_byte(*p++)); + + } + else + STRCAT(res, transchar_byte(*p++)); + } } } return res;
charset.c.patch
Description: Binary data