VirtualBox

Opened 14 years ago

Closed 13 years ago

#6046 closed defect (duplicate)

Key scancodes swapped with swedish keyboard layout

Reported by: wader Owned by:
Component: other Version: VirtualBox 3.1.2
Keywords: Cc:
Guest type: Linux Host type: Mac OS X

Description

Hello, im no keyboard expert but i want to share my findings

When i Linux as guest OS (Ubuntu 9.10) with a standard swedish USB keyboard (Dell keyboard) two keys are swapped. The keys are also swapped with the builtin swedish macbook keyboard.

Here is the standard swedish keyboard layout: http://upload.wikimedia.org/wikipedia/commons/e/e0/KB_Sweden.svg

The swapped keys are "§½" and "<>|", the "§½" key generates scancode 0x2c and "<>|" generates 0x56

The attached patch fixes this but im quite sure that it will mess things up for other layouts, but what is the correct way to fix this?

Attachments (2)

darwin-swedish-scancode-swap.patch (1.3 KB ) - added by wader 14 years ago.
source.tar (7.5 KB ) - added by Claudio Nieder 14 years ago.
Source for creating test program

Download all attachments as: .zip

Change History (16)

comment:1 by wader, 14 years ago

I can get a similar result using a ~/.Xmodmap file: keycode 49 = less greater NoSymbol NoSymbol bar keycode 94 = section onehalf

comment:2 by wader, 14 years ago

Sorry, should use wikiformatting

keycode 49 = less greater NoSymbol NoSymbol bar
keycode 94 = section onehalf

comment:3 by Claudio Nieder, 14 years ago

While it is possible to remap the keys in applications it looks like this is a geniun bug. According to http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc page 16 the key left to the "1" key should report scancode 0x29 and on page 17 you see that the extra key right to the left-shift key present on e.g. european keyboards should report keycode 0x56.

I wrote a tiny boot sector program which uses first Int16 to read the keyboard, then once you press the space key, will intercept scancodes sent to Int 15 (AH=4F) and finally once you held down a key long enough, will switch to read key values directly from the 8042 controller. In all instances I observe on my MacBook Pro (with OS X 10.6.2 and VirtualBox 3.1.2) that the scancodes are swapped with regard to Microsoft's specification.

by Claudio Nieder, 14 years ago

Attachment: source.tar added

Source for creating test program

comment:4 by Claudio Nieder, 14 years ago

Unpack source.tar in any directory.

nasm is used to create the binary. Specify its location in the first line of the Makefile.

The command to create the CD iso image is OS X specific.

Also if make is executed without arguments it tries to run a VM with name "test" assuming it is set up to boot from the CD image. So execute once make keyboard.iso to create the CD image, then you can set up manually a VM. Later on you can just type make.

To just assemble the source to create a boot sector you can type make keyboard.

comment:5 by Claudio Nieder, 14 years ago

I just remembered, that I have a PC USB keyboard, so attached it to my Mac and run my little test program. Same error appears. The wrong scancodes are reported in VirtualBox.

comment:6 by Claudio Nieder, 14 years ago

By the way I forgot to mention, that I am not having a swedish but a swiss keayboard. Also other layouts are affected as seen in other bug reports: #5936 swiss german, #5185 hungarian, #4006 german, #2996 german microsoft natural keyboard, #1494 unknown. Also #5543 notices that the keycode on the japanese keyboard is mapped wrongly: "Oh, I now noticed that the key actually is considered accent grave".

comment:7 by wader, 14 years ago

So as i understand it, Mac OS X reports the wrong scan code to VirtualBox?

Have you tested to boot your test program natively? same result?

comment:9 by Claudio Nieder, 14 years ago

Ah, I think I found the needed change to fix this. http://www.virtualbox.org/browser/trunk/src/VBox/Frontends/VirtualBox/src/darwin/DarwinKeyboard.cpp shows this:

106 	/**
107 	 * This is derived partially from SDL_QuartzKeys.h and partially from testing.
108 	 *
109 	 * (The funny thing about the virtual scan codes on the mac is that they aren't
110 	 * offically documented, which is rather silly to say the least. Thus, the need
111 	 * for looking at SDL and other odd places for docs.)
112 	 */
   ...
126 	    0x56,                       /* between lshift and z. 'INT 1'? */
   ...
220 	    0x29,                       /* Zen/Han (JIS)   0x68 */

The codes on those two lines would need to be swapped. Line 126 should read

126         0x29,                       /* between lshift and z. */

and line 220 should read

220 	    0x56,                       /* Zen/Han (JIS)   0x68 */

The line number are not part of the file but shown by the subversion browser and I have copied them too, so you can see which lines I am talking about.

comment:10 by wader, 14 years ago

Yes, that is what my patch does

in reply to:  7 comment:11 by Claudio Nieder, 14 years ago

Replying to wader:

Have you tested to boot your test program natively? same result?

Tried yes, results none. Problem is that Macs use EFI with a BIOS emulation and I suspect the BIOS emulation is not complete.

in reply to:  10 comment:12 by Claudio Nieder, 14 years ago

Replying to wader:

Yes, that is what my patch does

Oops I overlooked that one, as everybody else here usually tells about remapping the keys in X. Yes I think this would be the correct patch.

comment:13 by Claudio Nieder, 14 years ago

I notice 0x29 is present on three different lines: 166, 218 and 220. I suppose all three need to be replaced by 0x56. The first one (line 166) to fix the issue affecting all keyboards and the other two (lines 218 and 220) to fix also the japanese keyboards as mentioned in #5543.

comment:14 by Christian Pötzsch, 13 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #2996.

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use