On 5/8/06, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
Eric Arnold wrote: > 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. In Insert and command-line mode using CTRL-K <hit-the-Key> mostly works. You could make something that enters the key on the command line and use getcmdline() to get the key name.
This mostly works, but breaks certain contexts (i.e. in the middle of echo'ing a sequence of stuff): function! s:special_key_name( key ) exe "normal :let special_key_name='" . "\<c-k>" . a:key . "'\<CR>" return special_key_name endfunction
> 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. Why do you need a function to get the key name from a key code? What are you going to use that name for? Why didn't you have the name already?
When I receive a special key string from getchar(), I often store it, and want to display it later in recognizable format. There are also cases when I store the input'd key string into a configuration file, in which case the "\<keyname>" would be the most portable way to do this. In general, it seemed like strtrans() should be the function handling this.