Index: [thread] [date] [subject] [author]
  From: Andreas Beck <becka@rz.uni-duesseldorf.de>
  To  : ggi-develop@eskimo.com
  Date: Wed, 10 Nov 1999 18:19:11 +0100

Re: Keyboard Mapping routines (non-linux)

> As I worked on the windows port, I discovered that Direct Input
> returns keyboard scan codes.  Since I don't want to reinvent the wheel (
> too much anyway!!), what is the best, most common, or least complicated
> way to map a standard US keyboard. I suppose this also includes key
> modifiers such as shift, control, and alt.

Yes.

>     I quickly looked at the linux keyboard stuff, but I don't have a lot
> of the linux headers.

One possible way is to use a table like the lk201 driver does. The most
flexible solution I found up to now is to build a bitmask from the modifiers
like shift, ctrl and Alt.

Now you make a bunch of tables that come with a must-match mask and a don't
care one.

example: Say bit#0 is shift, 1 is ctrl, 2 is alt.

Now the first table would be something like
	must_match=0x06	/* ALt and Ctrl */
	dont_care =0x00 /* If shift is also pressed, it's different. */
	and then a list of all meaningful scancodes and their respective
	symbol code.
It is effective to have two possible implementations of that list: 
a) as an array from some minimum scancode to a max scancode that just
contains symbolcodes. This is accessed like: symbol=list[scancode-min]
b) as an array for scan->symbol mappings for "sparse" tables like Alt-Ctrl.
This is accessed like: for(x=0;x<max;x++) if (list[x].scan==scan)
symbol=list[x].symbol.

For making the label, I'd just suggest to assume the modifiers are all zero.
This is not perfect, as it e.g. uses lowercase letters, though uppercase 
ones are printed on the keyboard, but label isn't that important anyway.

CU, Andy

-- 
= Andreas Beck                    |  Email :  <andreas.beck@ggi-project.org> =


Index: [thread] [date] [subject] [author]