Date: Thu, 3 Mar 2005 15:40:25 -0600 (CST) From: Lars Eighner <eighner@io.com> To: Alejandro Pulver <alejandro@varnet.biz> Cc: freebsd-questions <freebsd-questions@freebsd.org> Subject: Re: Using META and DEL keys in console Message-ID: <20050303135450.H19517@goodwill.io.com> In-Reply-To: <20050303151945.07303710@ale.varnet.bsd> References: <20050301194338.3a49611d@ale.varnet.bsd> <20050301220822.F8622@goodwill.io.com> <20050303151945.07303710@ale.varnet.bsd>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 3 Mar 2005, Alejandro Pulver wrote: > Where is the (complete) list of scancodes and which keys produce them? > > If there is not, as I think, how can I know what scancode is produced by > each key in my keyboard (a program, maybe)? As a practical matter, for the console keyboard I generally work backwards from a known keymap (one of the distribution keymaps), and cut and try. man 5 kbdmap lists all the values you can assign to key combinations (note the "5" - otherwise you are likely to get man 1 kbdmap by default). Notice that you can use kbdmap or kbdcontrol to load a keymap to experiment with and you do not have to reboot to see what happens. I find this works very well with American PC keyboards where there are only a handful of keys that are in doubt, even with fairly esoteric models, like butterflies with two keypads. The distribution maps, after all, were not put together by crazy people, so the unshifted values of most of the keys are pretty logical. Oh, hell, this is so easy, here is the run down from the us.unix keymap: # scan # code base Deduced key associatied with scan code (i.e. not tested, YMMV) # ------------------------------------------------------------------ 000 nop 001 '`' ` 002 '1' keyboard (top row) 1 003 '2' keyboard (top row) 2 004 '3' keyboard (top row) 3 005 '4' keyboard (top row) 4 006 '5' keyboard (top row) 5 007 '6' keyboard (top row) 6 008 '7' keyboard (top row) 7 009 '8' keyboard (top row) 6 010 '9' keyboard (top row) 9 011 '0' keyboard (top row) 0 012 '-' keyboard (top row) - 013 '=' keyboard (top row) = 014 del top row backspace key 015 ht tab 016 'q' q - I trust you can figure out the letter keys 017 'w' 018 'e' 019 'r' 020 't' 021 'y' 022 'u' 023 'i' 024 'o' 025 'p' 026 '[' 027 ']' 028 cr keyboard Enter 029 clock Caps Lock 030 'a' 031 's' 032 'd' 033 'f' 034 'g' 035 'h' 036 'j' 037 'k' 038 'l' 039 ';' 040 ''' 041 esc Upper left escape key 042 lshift left shift 043 '\' backslash/bar key (wherever it is) 044 'z' 045 'x' 046 'c' 047 'v' 048 'b' 049 'n' 050 'm' 051 ',' 052 '.' keyboard . (next to comma) 053 '/' keyboard / (unshifted ?) 054 rshift right shift 055 '*' keypad * 056 lalt left alt 057 ' ' space bar 058 lctrl left ctrl 059 fkey01 F1 060 fkey02 F2 061 fkey03 F3 062 fkey04 F4 063 fkey05 F5 064 fkey06 F6 065 fkey07 F7 066 fkey08 F8 067 fkey09 F9 068 fkey10 F10 069 nlock Num Lock 070 slock Scroll Lock 071 fkey49 '7' keypad 7 072 fkey50 '8' keypad 8 073 fkey51 '9' keypad 9 074 fkey52 '-' keypad - 075 fkey53 '4' keypad 4 076 fkey54 '5' keypad 5 077 fkey55 '6' keypad 6 078 fkey56 '+' keypad + 079 fkey57 '1' keypad 1 080 fkey58 '2' keypad 2 081 fkey59 '3' keypad 3 082 fkey60 '0' keypad 0 083 bs '.' keypad . 084 nop 085 nop 086 nop 087 fkey11 F11 088 fkey12 F12 089 cr keypad enter 090 rctrl right control 091 '/' keypad / 092 nscr pscr Prt Screen (?) 093 ralt right alt 094 fkey49 non-keypad Home 095 fkey50 non-keypad up arrow 096 fkey51 non-keypad Page Up 097 fkey53 non-keypad left arrow 098 fkey55 non-keypad right arrow 099 fkey57 non-keypad End 100 fkey58 non-keypad down arrow 101 fkey59 non-keypad Page Down 102 fkey60 non-keypad Insert 103 bs non-keypad Delete 104 slock saver Pause (?) 105 fkey62 one of the windoz keys (104 keyboards) 106 fkey63 the other windoz key (104 keyboards) 107 fkey64 menu key (104 keyboards) 108 nop I might have the Pause and PrtScrn keys mixed up as I haven't actually tested this. Note: some "scan codes" are not associated with any keys on a PC keyboard and you do not have on a 101 keyboard the Windoz & menu keys. Also, many "Internet" buttons which are now common on the cheapest replacement keyboards don't do anything at all. What is called the "scancode" in FreeBSD console keymaps is not, evidently, the same thing as the very deep BIOS scan codes which you can (must) work with in some other operating systems. I think this is a good thing for PC users, but it may be otherwise for those with very obscure hardware. For the X keyboard there is the xkeycaps program (which is in the ports if not the base X package you are using), which can show the layout and keynumbers/keynames for most brands of PC keyboards and some usually sufficient generics. Notice, however that the X keynumbers are *not* always the same as what are called the scancodes in the console keymaps (although there are often sufficient similarities to mislead you into thinking they will be the same). Mapping the X keyboard and mapping the xterm keyboard are two different things. You should think long and hard about mapping the X keyboard - as there seems to be a lot of chaos in how applications and window managers fight over the keyboard and you don't really want to stir up that up any more than you can help. However, mapping the xterm so that applications that run in an xterm run just like they do in the console is a perfectly reasonable goal, and as I have mentioned can be done in the Xdefaults file. Moreover, these use more human-reasonable keynames rather than "scancodes." If you must map the X keyboard (not just the xterm) you can use xmodmap to map the X keyboard either a line at time or by loading a whole file (xkeycaps can output a file suitable for loading with xmodmap). I think some applications will thwart you by accessing the keyboard directly. -- Lars Eighner eighner@io.com http://www.io.com/~eighner/index.html 8800 N IH35 APT 1191 AUSTIN TX 78753-5266
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050303135450.H19517>