[Spice-devel] How to adapt keymaps for spice-html5

Christophe Fergeau cfergeau at redhat.com
Tue Mar 8 09:58:22 UTC 2016


Hey,

I experimented a bit with this..

On Mon, Mar 07, 2016 at 02:43:16PM +0000, Eric Grammatico wrote:
> The comments from the js file says:
> 
> * definition of the AT84/MF101/MF102 Keyboard
> 
> I had a look in Google to see a picture of a AT84.... Wahou ! Does someone believe a user will type
> on a AT84 using Xspice ? Last time I saw this kind of keyboard I was desperately trying to have
> something out of RPGII on an IBM36....

The relevant article would be
https://en.wikipedia.org/wiki/Scancode
These AT84 scancodes still show up with modern hardware/OSes, which is why
you are seeing this reference.

> 
> I believe this AT84 is defined somewhere overwriting my keyboard config in spiceqxl.xorg.conf. From
> my point of view there is no reason to modified any javascript if on server side it's reading the
> wrong keyboard model/layout. Any idea where to have further investigation ?

When you press a key on your keyboard, a scancode is sent to the OS,
which then maps it to the appropriate character depending on your OS
settings. For example, on a French or English keyboard, the A/Q keys are
in the same location and they return the same scancode, and then the OS
maps this scancode to an A or a Q depending on the keyboard layout which
was set.

SPICE tries to send these low level scancodes, so that everything works
as if this was an actual keyboard on the VM side.
However, this breaks down with spice-html5. spice-html5 cannot get the
raw scancode from a keypress, so instead it relies on a mapping from the
character returned by the OS to the scancode. This mapping will be
dependent on the current layout configured in the OS unfortunately, for
example for this A/Q situation I mentioned before..

For a given key on your keyboard, you can get the proper scancode to
send using
SPICE_DEBUG=1 remote-viewer spice://localhost:5900 |grep "key_event
press"
The 'keycode' value is the one you want.
Then in utils.js, I added a
console.log("Code: ", code)
to get_scancode()

Finally, you need to make sure that one of the scanmap has a mapping
from the utils.js code to the remote-viewer code.
For example, the diff below gives me proper output for the three keys right of
N on a French keyboard (the ,?  ;.   :/  keys). The client OS and the guest OS
have to be configured to use a French layout, otherwise this does not work (I
did this configuration using gnome-control-center).

@@ -198,7 +198,6 @@ common_scanmap[96]                 = KEY_KP_0;
 common_scanmap[110]                = KEY_KP_Decimal;
 common_scanmap[191]                = KEY_Slash;
 common_scanmap[190]                = KEY_Period;
-common_scanmap[188]                = KEY_Comma;
 common_scanmap[220]                = KEY_BSlash;
 common_scanmap[192]                = KEY_Tilde;
 common_scanmap[222]                = KEY_Quote;
@@ -209,6 +208,10 @@ common_scanmap[91]                 = 0xE05B; //KEY_LMeta
 common_scanmap[92]                 = 0xE05C; //KEY_RMeta
 common_scanmap[93]                 = 0xE05D; //KEY_Menu

+common_scanmap[58]                 = 52;
+common_scanmap[59]                 = 51;
+common_scanmap[188]                = 50;
+
 /* Firefox/Mozilla codes */
 var firefox_scanmap = [];
 firefox_scanmap[173]                = KEY_Minus;


Hope that helps,

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160308/8e596628/attachment-0001.sig>


More information about the Spice-devel mailing list