naTmeg / ScriptedAmigaEmulator

Amiga Emulator in javascript and HTML5
331 stars 63 forks source link

Can't type colon - keyboard is QWERTZ #36

Open goldnchild opened 2 years ago

goldnchild commented 2 years ago

Hi, I discovered your SAE recently and I have to say I am completely amazed that you can run an amiga emulator in a web browser.

I'm having a little problem though, I was fiddling with AMOS and could not type a colon : This makes it impossible to type in a program as you can't do any labels.

I tried shift + period, alt and ctrl and nothing seemed to work.

Also the keyboard seems to be QWERTZ, and my QWERTY usa keyboard is quite different.

Looking at https://github.com/naTmeg/ScriptedAmigaEmulator/blob/master/sae/input.js it appears that the mozilla keymap (I'm using firefox) is coded for QWERTZ

    const mozKeyCodeMap = {
...
          65:RAWKEY_A, //a
          66:RAWKEY_B, //b
          67:RAWKEY_C, //c
          68:RAWKEY_D, //d
          69:RAWKEY_E, //e
          70:RAWKEY_F, //f
          71:RAWKEY_G, //g
          72:RAWKEY_H, //h
          73:RAWKEY_I, //i
          74:RAWKEY_J, //j
          75:RAWKEY_K, //k
          76:RAWKEY_L, //l
          77:RAWKEY_M, //m
          78:RAWKEY_N, //n
          79:RAWKEY_O, //o
          80:RAWKEY_P, //p
          81:RAWKEY_Q, //q
          82:RAWKEY_R, //r
          83:RAWKEY_S, //s
          84:RAWKEY_T, //t
          85:RAWKEY_U, //u
          86:RAWKEY_V, //v
          87:RAWKEY_W, //w
          88:RAWKEY_X, //x
          89:RAWKEY_Z, //y               // Y mapped to Z
          90:RAWKEY_Y, //z
}

I see in a closed issue titled "Keyboard mapping on Mac is wrong. #34" there was some discussion about the Y and Z being swapped.

I made a little javascript to show the event values on a keydown event:

document.body.onkeydown = function(ev) { console.log("key:" + ev.key + " code:"+ev.code + " keyCode:"+ ev.keyCode); }

When I press the colon key I get:

key;: code:Semicolon keyCode:59

and if I look at the const mozKeyCodeMap, there isn't an entry for 59, so maybe adding

59:RAWKEY_SEMICOLON

might fix it?

naTmeg commented 2 years ago

For the QWERTY-problem it's normal behavior until 'C:SetMap' is used. IIRC it's necessary to swap Y/Z to make things work, but I'm not really sure, especially because you're already using an US-keyboard. I leave this issue open for further investigation..

I've added 59:RAWKEY_SEMICOLON, but didn't tested it.

Thanks for the report!

goldnchild commented 2 years ago

Hi Rupert! Thanks for the quick fix, I'm having great fun fiddling around with SAE.

I can now type a little AMOS program to test the joystick:

PRJOY: LOCATE 1,1 PRINT HEX$(JOY(1)) GOTO PRJOY

I tried using Workbench 2.1 and the included MicroEmacs to test out the keyboard (I'm assuming the default keymap is USA1 and I've got a usa 104 keyboard) (Also note that I'm using firefox under ubuntu)

On the number row: backtick gives an equals minus gives / equals is dead

qwerty row: y is z open, close bracket [ ] is dead

asdf row: ' is dead

zxcv row: z is y slash is dead

==================

backtick gives an equals key:` code:Backquote keyCode:192 currently 192:RAWKEY_EQUAL maybe change to 192:RAWKEY_TILDE

minus gives / key:- code:Minus keyCode:173 currently 173:RAWKEY_SLASH, maybe change to 173:RAWKEY_MINUS

equals is dead key:= code:Equal keyCode:61 (no 61) 60:RAWKEY_LESSGREATER, 63:RAWKEY_MINUS,

maybe add 61:RAWKEY_EQUAL

qwerty row: y is z open, close bracket [ ] is dead key:[ code:BracketLeft keyCode:219 key:] code:BracketRight keyCode:221 no keycode above 192 maybe add 219:RAWKEY_LBRACKET, maybe add 221:RAWKEY_RBRACKET

asdf row: ' is dead key:' code:Quote keyCode:222 no keycode above 192 maybe add 222:RAWKEY_QUOTE

zxcv row: z is y slash is dead key:/ code:Slash keyCode:191 no keycode for 191 190:RAWKEY_PERIOD, 192:RAWKEY_EQUAL maybe add 191:RAWKEY_SLASH

goldnchild commented 2 years ago

Trying to generate "fake" key presses in the javascript console to test some keystrokes:

keydown "a" key: SAER.input.keyPress({ keyCode:65,location:0,preventDefault:function(){}},true)

keyup for "a" key: SAER.input.keyPress({ keyCode:65,location:0,preventDefault:function(){}},false)

I was trying to figure out how to change the keyboard mapping while it's running, so I can change it on the fly.

steffest commented 2 years ago

If I might chime in: currently the keycode is fetched with var code = typeof e.keyCode == "undefined" ? e.which : e.keyCode;

I would suggest using the more recent e.code for this (https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code)

This was specifically added to solve these issues with different international keyboard layouts and it returns the "physical key" pressed, independent of keyboard layout. for emulators, this better reflects an actual hardware keyboard attached to the emulated machine, and it is then up to the amiga side to set the proper keyboard map in software to determine which character maps to which physical key. (both the Amiga and the javascript event.code default to qwerty)

naTmeg commented 2 years ago

I'm busy right now, but I'm looking into this sometime next week... Thanks guys for the tests and infos.

naTmeg commented 2 years ago

I've now completely dropped event.keyCode and switched to event.code. The defKeyCodeMap-/mozKeyCodeMap-tables are not used anymore. event.keyCode is now listed as deprecated anyway.

The version is still 0.9.13