HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 434 forks source link

PLUS key not being detected on QWERTZ layout #3090

Closed ACrazyTown closed 6 months ago

ACrazyTown commented 6 months ago

Code snippet reproducing the issue:

package;

import flixel.FlxState;

class PlayState extends FlxState
{
    override public function update(elapsed:Float):Void
    {
        if (FlxG.keys.pressed.PLUS) {
            trace("PLUS is pressed!");
        }
    }
}

Observed behavior: Pressing the PLUS key would cause the trace to be printed.

Expected behavior: Nothing happens.

I have a physical US QWERTY layout keyboard but I use the QWERTZ layout (called "Standard" on Windows). When I press the plus key on my keyboard anywhere else it properly types out a "+", however when I tried checking if plus was pressed in HaxeFlixel, I could never get it to work.

Thru OpenFL's keydown event I found that the key was being recognized as "43". I've tried checking the key thru some online keycode testers and all of them report it as "187" aka plus. It's only Flixel (or maybe OpenFL/Lime) that recognizes it as "43".

The worst part is that my keyboard is a TKL, meaning it has no numpad, so I'm unable to increase the volume on any HaxeFlixel project.

Geokureli commented 6 months ago

I assume this is what you're using? image

Even though the keys are named things like PLUS, it typically refers to the + key in the stanard English keyboard layout. Note that in software development keyboard events' keyCodes are not the same as charCodes, in fact the distinction only becomes more clear when dealing with non-standard-english keyboards.

I haven't tried but I assume your Z key is still on key 90, but key 90 was moved in your keyboard, whereas + was moved to a different button. I think this is made even more confusing by the fact that there really is no PLUS key, if anything, there's an EQUAL key, but we just call it PLUS for some reason. if you wanted to get the plus on the keyboard pictured, i would use THREE

To fix, you can use openfl keyboard events to get the charCode, I believe this would still require you hold shift when you press 3, or you can simply press the Ü key on your keyboard, which might work, since it's in the same location as my + Here's a handy keycode guide, you're looking for key 187

ACrazyTown commented 6 months ago

I use the Croatian version of QWERTZ: image

Pressing the plus(?) key right next to backspace returns 187 on the website you linked and also a few others I've tried. Only Flixel seems to recognize it as key 43 for whatever reason

Geokureli commented 6 months ago

sorry for the misunderstanding, I'll look into this, I would also raise this issue with lime/openfl

ACrazyTown commented 6 months ago

I tried making a little example project in C++ and sure enough SDL2 also detects the key pressed as 43.

Looking at SDL2's documentation 43 seems to be SDLK_PLUS, which would be correct and Lime's KeyCode class also defines PLUS as 43.

OpenFL's Keyboard class has some commented out code for the plus key which I'm thinking may be the cause. Should I make an issue on OpenFL's repository?

Geokureli commented 6 months ago

OpenFL's Keyboard class has some commented out code for the plus key which I'm thinking may be the cause. Should I make an issue on OpenFL's repository?

Yes, please, link this issue in it and link the code you're referring

ACrazyTown commented 6 months ago

After digging around a bit more I'm confused as to what the issue is. Both SDL and Lime detect the PLUS key as 43, OpenFL's Keyboard has only one mention of PLUS but it's commented out and it's also 43.

It only seems to happen on native targets (I've only tried Hashlink so far), on HTML5 the keycode is 187.

I've found this line in FlxKeyboard that seems related but it's Mac only for whatever reason. Removing the Mac conditional fixes the issue. Is there a reason why it's Mac only or?

Geokureli commented 6 months ago

I've found this line in FlxKeyboard that seems related but it's Mac only for whatever reason. Removing the Mac conditional fixes the issue. Is there a reason why it's Mac only or?

@NeeEoo, care to comment, re: https://github.com/HaxeFlixel/flixel/pull/2987

NeeEoo commented 6 months ago

I didnt know it happened on non mac platforms too, feel free to remove the conditional