French keyboard layout & switching

You can now use a french keyboard layout and switch bewteen keyboard layouts.
Use the "loadkeys" command.

Thanks to Marc Denty.

UK keyboard added

The UK keyboard layout has been added.

Thanks to Mark Hale.

new keyboards layouts

Hi, how can I create new layouts. can you write a small docu and add it to the docus?

New keyboard structure

I have just made the danish keyboard interpreter, but have also made the way of setting up the layout easier, plus better support for multile VK on the "same" keys and better support for the dead keys. Thus have made changes in the KeyboardInterpreter and I have planed to make te changes in the default/US version too, but I would hope that someone would make the changes in the FR/UK and now ES also, if not there could go some more time before my changes comes in effect or the FR/UK/ES versions will work. I noted a lag of support in the caps lock, if I get the time, I'll fix that too.


Martin, Have you commited the new structure to CVS ?

I don't know how are made KeyboardInterpreter but I can help you because I have a french keyboard (loadkeys FR fr)

Maybe you can also add support for NumLock (it seems not supported with my keyboard).


New structure have been added

I have just added the new keyboard layout to CVS, the DK/UK/US/FR versions are converted, but the ES version is pt. missing/brooken. If I get the time, I convert it too, but I would like some else to make it. The french keyboard is also giving me some "problems", do it have DEAD_ACUTE and DEAD_GRAVE keys? And how about the € sign in the FR/UK versions?
I have just out commeted the old settings just as a reference.
The CapsLock are now working, but it looks like the arrow keys are a little wrong (on the danish keyboard and on my laptop), but I have not change it in the US/UK/FR versions (feedback is needed). It could be a matter of the NumLock, I will connect a normal keyboard next week and look at the NumLock too. Please check your new keyboard layouts.

For new keyboard layouts, one maybe take a look in the danish/DK version.


Implementation broken!

Do not update this version, the extended keys do not work anymore.

Keys are not working?

Please give me some more info.


cursor-keys, pgup/down

And probably more extended keys.

I've tested on both US & FR keyboard interpreters.

I see

It's the call to the deriveKeyCode method and a check on vk != 0. I removed the vk != 0 as it is wrong not to accept this as 0 = KeyEvent.VK_UNDEFINED, as example the danish å has vk = KeyEvent.VK_UNDEFINED. I think it ok to remove this.

The deriveKeyCode looks like a small hack, it looks like it's the problem I wrote about in the danish keyboard layout. Please check the danish version too, the cursor/arrow keys are working here. In the old US vkMap[72] = KeyEvent.VK_NUMPAD8, but this is changed in the deriveKeyCode to:
case 72:
vk = KeyEvent.VK_UP;
The vk value is now taken from the Key on the scancode in the Keys object.

As I see it, the main problem is the vkMap was/is wrong in most layouts. Please correct me if I'm wrong.
The call to the deriveKeyCode should be drop in the version I commited.


Once more

I have made changes and have just commited once again. The vk for extended keys are taken from the deriveKeyCode method and the char value it taken from the interpretExtendedScanCode method.

The ES version have to be corrected, it's now using the DK version, but I guess many of the keys are on the right place.


How I did it

You need to write an org.jnode.driver.input.l10n.KeyboardInterpreter class (under core/src/driver). In that class, you override the initVkMap() method. There are three array mappings you need to setup:
1) vkMap[scanCode] = AWT key (i.e. physical keys to virtual keys).
2) lcharMap[scanCode] = lowercase screen character (i.e. what character should be produced without shift button).
3) ucharMap[scanCode] = uppercase screen character (i.e. what character should be produced with shift button).

Keyboard scan codes generally follow the physical row layout of the keyboard. The five international key scan codes are:
INT1 = 0x56
INT2 = 0x2B
INT3 = 0x73 (mainly Japanese)
INT4 = 0x7D (mainly Japanese)
INT5 = 0x7E (mainly Japanese)


I have added a 4th array for extended keymapping with AltGr (the Alt key on the right side of space bar). For french layout it is very usefull.
I also added when using loadkeys without parameter, it prints the current keyboard layout used.
But, we need a new object design for KeyboardInterpreter to allow more flexibility as I explained on the devel mailing list

Possible API refinement

Sounds like a good idea. One possible problem, what happens if a keyboard doesn't support a particular modifier? Maybe a getScanMapping(modifier, scancode) method would be better, with the if-else-if-else flags statement the responsibility of the keyboard interpreter. That way, interpreters need only implement the modifier arrays they support.

> if (vk != 0) {
> char ch = -1;
> ch = interpretExtendedScanCode(flags, scancode, lastscancode);
> if(ch == -1) {
> if ((flags & InputEvent.SHIFT_DOWN_MASK) != 0) {
> ch = getScanMapping(SHIFT_MODIFIER)[scancode]; >// Will define SHIFT_MODIFIER as static String
> } else if((flags & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
> ch = getScanMapping(ALT_GRAPH_MODIFIER)[scancode];
> } else {
> ch = getScanMapping(NO_MODIFIER)[scancode];
> }
> }
> long time = System.currentTimeMillis();
> lastScancode = scancode;
> return new KeyboardEvent(released ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED, time, flags, vk, ch);
> } else {
> lastScancode = scancode;
> return null;
> }

Dead keys support added

Update your CVS, I've done something similar for dead keys management.
Feel free to update it for your needs.



What is the DvorakKeyboardInterpreter used for? I have made some changes to the KeyboardInterpreter and are correcting the descents,
if it's not used I will jump over the DvorakKeyboardInterpreter.



I had used the DvorakKeyboardInterpreter for my interactive jnode sessions. Dvorak is a keyboard layout, like qwerty. The class DvorakKeyboardInterpreter was a quick hack that mostly worked, I guess I am the only one using it, you can ignore it (put TODO's in or something intelligent), if API is too different and a more intelligent refactor is required, you can just get rid of DKI for now.

Sam Reid

I added US layout, please do

I added US layout, please do change it if you need it.