SFML community forums

General => Pull Requests & Testing => Topic started by: Elias Daler on April 09, 2018, 09:04:11 am

Title: Scancodes (Windows, Linux, Mac testing needed)
Post by: Elias Daler on April 09, 2018, 09:04:11 am
Hello, everyone!

The scancode feature is implemented on Windows, Mac and Linux and needs a lot of testing.

Links:
#1325 (https://github.com/SFML/SFML/pull/1235) by Hiura - created API for scancodes and Mac implementation
#1294 (https://github.com/SFML/SFML/pull/1294) by JohnyPtr - Windows implementation
#1400 (https://github.com/SFML/SFML/pull/1400) by Elias Daler - Linux implementation

Purpose
Scancodes are a very important feature that's been asked to be implemented in SFML for a long time. It gives developers a layout independent way of reading keyboard input. Suppose you're using standard "WASD" walking input scheme in your game. If you just say "if pressed sf::Keyboard::Key::A then go left", it'll work as expected only on a QWERTY and a bunch of layouts where "WASD" is in the place gamers usually expect it to be. But, it'll work wrong on AZERTY layout, which has "A" where "Q" on QWERTY is.

Scancodes prevent this problem. If we say "if pressed sf::Keyboard::ScanA then go left", we're telling something like "if pressed the key which is in the place where A on QWERTY keyboards is then go left".

Testing
Testing can be easily done with this repo (https://github.com/mantognini/SFML-Test-Events/tree/scancode). Don't forget to switch to branch "scancode".

Testing is especially important if you have non-QWERTY layout. The more non-traditional it is, the better. Another good thing to test for is weird keyboards with non-grid layouts.

Things to test:

There are a bunch of keys which will cause the window to lose focus: System/Win key, VolumeUp/Down keys, etc. These keys need to be tested separately in your code. For example, something like this:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::ScanVolumeUp))
    std::cout << "VolumeUp pressed!\n";

After you've done testing, please post about how it worked for you in this thread. If you have some problems, feel free to ask any questions.

New stuff added to SFML's API
You also now will have "scancode" field filled alongside with "key" in KeyPressed and KeyReleased events.

Examples of usage:
sf::Keyboard::Key key = sf::Keyboard::unlocalize(sf::Keyboard::ScanQ); // Q on QWERTY, A on AZERTY
sf::Keyboard::Scancode scancode = sf::Keyboard::localize(sf::Keyboard::A); // ScanA on QWERTY, ScanQ on AZERTY
sf::String str1 = sf::Keyboard::getDescription(sf::Keyboard::ScanQ); // "Q" on QWERTY, "A" on AZERTY
sf::String str2 = sf::Keyboard::getDescription(sf::Keyboard::ScanSpace); // "Space" on all layouts

It'll be very nice to test this feature not only using Hiura's test program, but in your code as well. Thanks to everyone who'll take the time to test this!
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: Ceylo on April 09, 2018, 11:00:57 pm
First of all congrats for the huge work! (and then good luck for the bugfixes :D )

I've tested on macOS with a french mac keyboard, exactly this layout:
https://store.storeimages.cdn-apple.com/4662/as-images.apple.com/is/image/AppleInc/aos/published/images/M/Q0/MQ052F/MQ052F?wid=2000&hei=2000&fmt=jpeg&qlt=95&op_usm=0.5%2C0.5&.v=1496359289903

Will give the results line by line, starting from the top of the keyboard:
First line:
(click to show/hide)

Second line:
(click to show/hide)

Line 3:
(click to show/hide)

Line 4:
(click to show/hide)

Line 5:
(click to show/hide)

Line 6:
(click to show/hide)

Additionally (but maybe out of scope), I found a few buggy combinations:
1. Holding left ctrl + right ctrl prevents right shift from being detected, and also prevents usage of all keys of 2nd line up to ScanEquals, as well as numpad keys 4, 5, 6 and +
2. Holding left alt + right alt prevents usage from all letter keys in 4th keyboard line, as well as numpad 7, 8, 9 and - keys

Note that both (1) and (2) don't not look to be specific to SFML, TextEdit app provided by Apple does the same weird thing.
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: Elias Daler on April 09, 2018, 11:26:52 pm
Thanks a lot for such intense testing. :D

Hiura, the weird "@<" key is most likely to be ReverseSolidus. At least that's how it worked on Linux for Ceylo.
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: Hiura on April 10, 2018, 08:36:49 am
Thanks a lot for the feedback ! I guess I have to put my hands on an external keyboard to properly test everything... but this will take time. If you/anyone wants to chip in code, please do not hesitate. :)

As for "buggy combinations", this is a known limitation of the wiring of most keyboard, regardless of the brand. The invalid combinations depends on the wiring so it's not consistent across keyboards but we can't do a thing about it.

PS: I've fixed SFML-Test-Events scancode branch... sorry it wasn't up to date!
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: Jonny on April 10, 2018, 07:05:52 pm
Just for the record (getting my excuses in :P) the windows PR I did was done In a bit of a hurry and I haven't had access to a windows machine since then to fix it up, so it may be a little messy, don't feel bad about tearing it apart, I won't be precious about it!
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: Elias Daler on April 20, 2018, 12:55:35 pm
Test Windows implementation. Some bugs found:

On QWERTY:

* Tilde/Grave accent is identified as ScanBackslash
* F11 and F12 don't have a string description
* Backslash (the key left to Enter) is detected as ScanDash and getDescription returns "`"
* Volume Up/Down, Find and Mute buttons are "Unknown"
* Keyboard enter is "ScanReturn", though it should be "ScanEnter". Numpad enter should be "ScanReturn" (see comments in enum)

Other keyboard layouts work, but I wonder if "ScanReverseSolidus" will be identified correctly. Someone who has a keyboad with this key (it's the one right to the LShift, it usually has "<>|" on it should test it.

* And getDescription returns translated descriptions for Ctrl, Shift, Alt, Home, PageUp, etc. in non-English layouts. E.g. if I turn on AZERTY, I get descriptions in French. Not sure if it's a behaviour we want... We'll discuss it in Scancode PR (#1235).
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: Tym17 on August 12, 2018, 09:11:07 pm
Hello,
I tried to carry out the tests on Windows and here are my results by using my default keyboard which have AZERTY layout:

Line 1:
(click to show/hide)

Line 2
(click to show/hide)

Line 3:
(click to show/hide)

Line 4:
(click to show/hide)

Line 5:
(click to show/hide)

Line 6:
(click to show/hide)

Switching numpad off, pressing on the keys then activating it again:
(click to show/hide)

I tried to change my keyboard layout to QWERTY and it seemed to work great but I don't know where the keys would stand on my keyboard except for the QWERTY and M keys and they worked fine. Also two interesting things, I have a key named 'Alt Gr' that triggered 2 key presses at the same time and my enter key was labelled as numpad enter key and vice-versa but this is probably due to the wiring of my keyboard. I also added some kind of comment after the key log preceded by double slashes when something seemed odd to me.

I hope this could help you! :)
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: RameyNoodles on March 18, 2020, 02:08:12 am
Any updates on this? How do I get a build with this feature?
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: binbinhfr on April 22, 2020, 10:21:58 am
any news on this ?
I still don't figure out how to implement a keyboard customisation in my game... (allowing AZERTY / QWERTY users to remap keys).
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: eXpl0it3r on April 22, 2020, 02:35:53 pm
For another time, please don't bump all threads related to your specific situation. ;)

As mentioned (https://en.sfml-dev.org/forums/index.php?topic=13692.msg172788#msg172788) I'm slowly working on updating the mentioned PR: https://github.com/SFML/SFML/pull/1235
Title: Re: Scancodes (Windows, Linux, Mac testing needed)
Post by: binbinhfr on April 22, 2020, 05:49:43 pm
For another time, please don't bump all threads related to your specific situation. ;)

Yes, sorry, I thought it might notify different users who subscribed to these different threads and who could answer my question... But you received ALL the notifications  :( .