joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.81k stars 383 forks source link

Swapped keys and wrong right Alt keycode on my ACER Aspire V3-371-53LT laptop #915

Open Laci60 opened 6 years ago

Laci60 commented 6 years ago

Description of bug On my ACER laptop following keys are swapped: ` with 0 - with / y with z

The right Alt (named AltGr) key produces a left Ctrl+right Alt keystroke (at least in mapper)

To Reproduce Steps to reproduce the behavior:

  1. Go to keymapper
  2. Push the ` button - 0 will be highlighted and vice versa
  3. Push the - button - / will be highlighted and vice versa
  4. Push the y button - z will be highlighted and vice versa
  5. Push the right Alt button - left Ctrl and right Alt will be highlighted

Expected behavior It is expected to highlight key corresponding to pushed button. Swapped keys can be repaired with a keymap definition file, right Alt key can not (in my opinion).

Screenshots No need for screenshot.

Environment

Additional context If I boot MS-DOS 6.22 in DOSBox-X and use the hungarian keymap I am not able to write characters which need AltGr button: * ; $ < > # & @ } [ ] \ | etc. In Windows 3.11 and Windows 95 this phenomena exist only on DOS boxes (for example Write and WritePad works excellent).

joncampbell123 commented 6 years ago

DOSBox-X removed the SDL1 library hack of mapping the US keyboard layout for itself.

I will be writing a document for other developers on how to add foreign keyboard layouts to DOSBox-X.

joncampbell123 commented 6 years ago

The latest commit adds a file named 'README.keyboard-layout-handling' that should provide a good starting point on how a developer can add additional keyboard layouts.

Modifications are involved in both DOSBox-X and the SDL1 library included in the tree.

Laci60 commented 6 years ago

Thank you very much for README. I do not want to deal with swapped keys - this problem can be solved by keymapper. I want to make right Alt key not to be left Ctrl + right Alt. There is no key without VK* code on my laptop. right Alt has the VK code 0xa5 and key name is Alt. I do not understand why this button produces Ctrl+Alt event. screenshot01 And no, I do not press left Ctrl but right Alt button alone! Why mod=40h? Is not this problem exist with US keyboard? What is that VK_ code there? PS: The right Alt button is not remapped - I can not show it with screenshot.

Laci60 commented 6 years ago

I am trying to understand how DOSBox-X handle the keyboard with SDL but it is not a success yet...

Laci60 commented 5 years ago

In Windows AltGr works well. In DOS or Windows DOSbox it behave like Ctrl+Alt. I can't recognise what is the matter.

Laci60 commented 5 years ago

New observation: In SDL2 version the above mentioned keys are not swapped, although the Right-Alt key is wrong (produces Ctrl+Right-Alt keystroke in mapper).

emendelson commented 5 years ago

I don't know if this helps, but: Ctrl-Alt on a US keyboard sends the same scan code that Right-Alt (AltGr) sends on non-US keyboard. This may (or may not) help sort out the issue.

aaaaaaaCatOnMyKeyboard commented 2 years ago

sorry for bringing this old post to front again. i'm struggling also with this issue and it seems that any DOSBox fork, build and version, has this problem. you can reproduce it by installing another keyboard layout like GER or FRA, set it active and try to use or rebind the right ALT key. it will not work, even if you use the Windows on-screen keyboard.

rderooy commented 2 years ago

Have you tried using the SDL2 version of DOSBox-X? It should work fine with the right Alt key (Alt-Gr).

maron2000 commented 2 years ago

On Windows, if you press Alt-Gr, it will act as you press Left Ctrl & Right Alt, not only DOSBox-X. altgr

aaaaaaaCatOnMyKeyboard commented 2 years ago

SDL2 has the same problem and it's seems it is not DOSBox specific as i read here.. the only workaround is to switch the keyboard to "ENG" in taskbar or by hokey "Left Alt + Shift"

rderooy commented 2 years ago

I don't know on Windows. On my linux systems AltGr works just fine with a non-US keyboard layout with the SDL2 DOSBox-X. With the SDL1 builds, it does not work.

aaaaaaaCatOnMyKeyboard commented 2 years ago

i've checked the controller mapping feature of some emulators on Windows. MAME amd BizHawk detect it correctly, RetroArch doesn't and it uses SDL2.

btw. i found this: https://github.com/ja2-stracciatella/ja2-stracciatella/issues/539#issuecomment-306363754

i'm not a developer, but is this something which could work for DOSBox?

maron2000 commented 2 years ago

AltGr works fine on Ubuntu SDL1 (I recommend changing usescancodes=true or you need to remap your mapper settings a lot). I think this issue is only related to Windows, which returns two keys instead of one when AltGr is pressed as I mentioned above. keyb

aaaaaaaCatOnMyKeyboard commented 2 years ago

AltGr works fine on Ubuntu SDL1 (I recommend changing usescancodes=true or you need to remap your mapper settings a lot). I think this issue is only related to Windows, which returns two keys instead of one when AltGr is pressed as I mentioned above. keyb

thanks for testing this in Linux. switching the keyboard layout within DOSBox-X is not the problem, but if your keyboard in Linux is configured with german layout and works, then it must be an issue with SDL in Windows.

usescancodes=true or usescancodes=false doesn't change anything

maron2000 commented 2 years ago

@aaaaaaaCatOnMyKeyboard Yes, youre right. I was just responding to @rderooy since he said that AltGr in SDL1(Linux) didn't work.

Absolutely, usescancodes option will not work on Windows, in terms of getting rid of the Ctrl key. And, I have never said that this is a problem of switching between layouts, but the problem is that Windows returns two keys which SDL will NOT ignore the unneeded one.

aaaaaaaCatOnMyKeyboard commented 2 years ago

@maron2000 ok.. but did you have an idea how to fix this or should we give up here? there was a solution from the user Tercus if you open the link from my previous post:

    case SDLK_LALT:
    case SDLK_RALT:
    case SDLK_MODE:
        gfKeyState.set(ALT);
        break;

did you know if this could be a workaround?

maron2000 commented 2 years ago

@aaaaaaaCatOnMyKeyboard I haven't tried it but I don't think it will work because the patch doesn't handle anything about Left Ctrl key. The person showing the patch is possibly talking about Linux since the logs he/she shows in other comments are Linux.

aaaaaaaCatOnMyKeyboard commented 2 years ago

ok, maybe someone will find a solution. i can live with it... thanks for your contribution

rderooy commented 2 years ago

@maron2000 You are right, I had not tried AltGr in a long time on SDL1 builds, and it does work, at least on Linux. When i switch to a layout that uses it, such as keyb uk and press AltGr 4, I get the Euro symbol.

maron2000 commented 2 years ago

For experimental purpose, I made a patch to ignore Left Ctrl if followed by Right Alt (That means AltGr is pressed). e2bbd84a0b753745093c24505f3a77b490df4311 Seems to work well for PCDOS 6.3. AltGr works as expected, and Left Ctrl as well (such as Ctrl C) To merge this to the main repository, I think it should be an enabled as an option for users having AltGr, and disabled for others. I dont know how to do that, actually.

altgrtest

You can try the test builds VS x64 https://github.com/maron2000/dosbox-x-1/suites/6542783967/artifacts/244255807 VS x86 https://github.com/maron2000/dosbox-x-1/suites/6542783975/artifacts/244251844

aaaaaaaCatOnMyKeyboard commented 2 years ago

@maron2000 it works now in SDL1 and SDL2 ok.. the mapper editor will not correctly detect it as Right ALT, but the key is usable now. thank you !!! :-)

maron2000 commented 2 years ago

@aaaaaaaCatOnMyKeyboard Thank you for testing. Yes, this patch is not perfect, such as the glitches in mapper editor as you mentioned, and there should be delays in pressing Left Ctrl key, since the patch waits for the next key before determining it is pressed. So while typing words may not be a problem, if you play a game that pressing Left-Ctrl key matters, I recommend disabling my patch. Anyway, some part is beyond my skill to integrate this, so we may want some help from the devs.

rderooy commented 2 years ago

My idea would be to only do the check on Windows, and only if the keyboard layout is not US, as the DOS US keyboard layout does not support AltGr, but I think all non-us keyboard layouts do.

aaaaaaaCatOnMyKeyboard commented 2 years ago

My idea would be to only do the check on Windows, and only if the keyboard layout is not US, as the DOS US keyboard layout does not support AltGr, but I think all non-us keyboard layouts do.

in the last resort, this should be fixed in the SDL librarys for Windows, so that other Projects incl. the other DOSBox forks benefit from it. This is only a workaround..

maron2000 commented 2 years ago

@aaaaaaaCatOnMyKeyboard Indeed, and you know who to ask to fix it.

maron2000 commented 2 years ago

@rderooy I agree with you, and the experimental patch(hack) only affects Windows binary. Not all non-us keyboards have AltGr(including my JP keyboard) so I assume it better to make it an option to enable the hack.

aaaaaaaCatOnMyKeyboard commented 2 years ago

@aaaaaaaCatOnMyKeyboard Indeed, and you know who to ask to fix it. done. https://github.com/libsdl-org/SDL/issues/5685