⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme.keymap

📁 linux 下svgalib编的一个界面程序示例
💻 KEYMAP
字号:
** Svgalib keyboard scancode remapping: the Readme **** IntroductionAfter a poll on Slashdot.org about keyboard layouts, I decided to switch fromQWERTY to the Dvorak simplified keyboard. (Such is the power of Slashdot!) Itwas easy to switch the keymaps used by the console and X and even LILO, butsvgalib programs that used raw keyboard weren't affected since they interpretthe keyboard scancodes into characters themselves - often assuming a standardUS keyboard with QWERTY layout.In order for my machine to present a ``unified front'' with a single consistentkeyboard layout, I added to svgalib the ability to remap scancodes. This isdone in keyboard_getevents(), before the event handler is called, so it willwork whether or not a program provides its own handler. Programs that do notuse raw keyboard are not affected, so by setting both the console and svgalibitself to use the same keymap a consistent keyboard layout is available to allsvgalib programs.** BackgroundWhen you press or release a key on your keyboard, it sends a byte of data toyour computer. The top bit indicates whether the key was pressed or released,and the lower seven bits hold the scancode, a number that uniquely identifiesthe key. A program on the computer interprets these scancodes as representingcharacters (`A', `%', etc) or actions to be taken (`Page Up', `Back Space') ormodifiers that alter the interpretation of other keys (`Shift', `Alt', etc).Most programs do not perform this interpretation themselves, but leave it upto some other piece of software: the system BIOS, or the operating system,or the graphical user interface system.On Linux this is normally done by the kernel or by the X server for X clients,but this doesn't meet the needs of some programs (especially games) whichcare more about whether a key is up or down than what it means and treat themodifiers the same way as other keys. These programs open the keyboard in `raw'mode and deal directly with scancodes.The problem comes because these programs often do need to interpret the keysinto characters, or it is important for a certain key to be identifiable tothe user as being associated with a certain key. For instance, a game playermight need to type a description of a saved game or be directed to press acertain key to activate a game feature. Interpretation of keyboard scancodescan be difficult since there are many different keyboard layouts which do nothave the same associations between scancodes, modifiers, characters, andcommands. So the author of the program must choose between writing a complexand customizable conversion routine that can handle any layout the user mighthave, and a simple routine that is hard-coded to use a single layout. In thelatter case, users of other keyboard layouts will encounter numerousdiscrepancies between what he or she tries to type and what the programinterprets.** How it worksSvgalib's scancode conversion is meant to at least partially fill this gap byconverting the scancodes that the keyboard produces to equivalent, or nearlyequivalent, scancodes for the keyboard layout that the program expects. Theprogram then (hopefully) interprets the new scancode into the intendedcharacter.As an example, let us consider a US keyboard with Dvorak layout and the gameQuake, which expects a US keyboard with QWERTY layout. Both layouts have thesame scancodes for each physical key, but different characters are produced.For intance, the first row of letters produces the scancodes 16 through 27, buton QWERTY this produces the charaters qwertyuiop[] while Dvorak produces',.pyfgcrl/=. Thus when the Dvorak letter `p' is pressed, the scancode 19is interpreted by Quake as the letter `r', which occupies scancode 19 on theQWERTY layout.The solution lies in the fact that svgalib acts as an intermediary between thekeyboard and the program and has the opportunity to present a differentscancode to the program than the keyboard produced. In this case we tell Quakethat the scancode was not 19 but rather 25, which is the letter `p' in theQWERTY layout, so when Quake interprets the scancode the correct character isproduced.** The keymap filesIn order to know what scancodes to convert to what other scancodes, a keymapfile is read which lists scancodes produced by the keyboard and theirequivalents in the layout expected by the program.A program called svgakeymap is provided to generate these maps from thekeytable files in /usr/lib/kbd/keytables; you must have perl for it to work.Creating a keymap file with svgakeymap is easy; to make a map to convertscancodes from a US Dvorak keyboard to a US QWERTY keyboard as for our exampleabove:  svgakeymap dvorak us > dvorak-us.keymapThe path and .map and .gz suffixes are automatically added if necessary. Ifyour keytables are stored elsewhere, specify a complete path. If only onekeytable is specified, a keymap is generated that performs no conversions butcontains the correct key names so you can specify scancodes used by fakekeyboard and mouse events by name instead of by number. If none are specified,this is done for the standard US QWERTY layout.dvorak-us.keymap and default.keymap (the US QWERTY layout) are provided withthe svgalib distribution and can serve as an example if you wish to make yourown keymap files manually or create an improved generator.** ConfigurationYou can specify a keymap to use for all svgalib programs (keeping in mind thatonly those that use raw keyboard are affected) by putting a line like this intolibvga.config or ~/.svgalibrc:  kbd_keymap /etc/vga/dvorak-us.keymapYou must specify a complete path to the keymap file. If no keymap is specified,no conversion is performed.You can also override the global keymap by setting the environment variableSVGALIB_KEYMAP to point to the appropriate keymap file. This can be useful ifsome programs support alternate keymaps directly but not others, or ifdifferent users use their own keyboard layouts based on preference.** Security issuesIt can be dangerous to let users arbitrarily reassign keyboard scancodes; forinstance all keys could be routed to an unused scancode, making the consoleunusable. To prevent this, put the option kbd_only_root_keymaps intolibvga.config; only keymaps owned by root will be accepted, so the availablekeymaps can be limited to safe ones.** Bugs and limitationsThere are no known bugs, but there probably are some. If you find any pleaselet me know at brion@pobox.com.Limitations however we definitely have. The scancode conversion performed isvery simple, and can only achieve 100% success when the keyboard layouts beingconverted between differ _only_ in arrangement of keys while producing the samecharacters from each key. Example: the de facto standard Dvorak keyboard hasthe left and right brackets (`[' and `]') on separate keys, with the curlybraces (`{' and `}') produced by those keys when shifted. The standard QWERTYkeyboard produces those characters the same way, the only difference is thatthe keys are a row higher on Dvorak; switching the scancodes around results inproper character interpretation. However the official ANSI standard Dvoraklayout has tho two brackets on _the same key_, one regular and one shifted.The curly braces similarly have their own key. These cannot be properly mappedby scancode to the QWERTY keyboard since they produce different charactersin conjunction with modifiers, and the wrong character is produced by theprogram.This could be worked around by interpreting the modifiers in svgalib andsimulating the proper modifier/character keypress/release sequences, but itwould be very complex and would do nothing to help the situation wherecharacters on the physical keyboard layout do not exist on the target layout(quite likely when dealing with national or language-specific keyboards);they cannot be converted into any key sequence since they do not exist.Ultimately it might be better to set up a ``medium-rare'' keyboard mode wherekeys are interpreted into characters but ``raw''-style non-interpreted keypress and release events are available.** Further informationThere isn't really any further information right now unless you want to Use TheSource... More to come in the future. If it does you'll find it at:  Brion Vibber's Svgalib Stuff - http://pobox.com/~brion/linux/svgalib.html-- brion vibber (brion@pobox.com)   3 July 1998

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -