Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scancodes (Windows, Linux, Mac testing needed)  (Read 31549 times)

0 Members and 1 Guest are viewing this topic.

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Scancodes (Windows, Linux, Mac testing needed)
« 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 by Hiura - created API for scancodes and Mac implementation
#1294 by JohnyPtr - Windows implementation
#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. 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:
  • Alphanumeric buttons. See that scancode corresponds to QWERTY layout. Key description should depend on your layout and produce the same thing that you see when you type into a text editor
  • Toogle NumLock on and off and see if numpad keys are correct. In a lot of keyboards if NumLock is turned off then "2" on Numpad acts as "Down"
  • Try pressing F1-F12, Space, Tab, Enter, Backspace, Delete, etc. and confirm that they are correctly displayed
  • Try pressing Ctrl and Alt keys. They have "Left" and "Right" variants and this should be shown in the test program
  • Try changing your keyboard layout in system settings. For example, switch to DVORAK and test that the keys are still identified correctly

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
  • Keyboard::Scancode enum
  • Keyboard::isKeyPressed(Keyboard::Scancode)
  • Keyboard::Key Keyboard::localize(Keyboard::Scancode)
  • Keyboard::Scancode Keyboard::localize(Keyboard::Key)
  • String Keyboard::getDescription(Keyboard::Scancode)
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!
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #1 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.
Want to play movies in your SFML application? Check out sfeMovie!

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #2 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.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #3 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!
SFML / OS X developer

Jonny

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #4 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!

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #5 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).
« Last Edit: April 20, 2018, 12:58:03 pm by Elias Daler »
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Tym17

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • My blog
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #6 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! :)
« Last Edit: August 12, 2018, 09:16:12 pm by Tym17 »

RameyNoodles

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #7 on: March 18, 2020, 02:08:12 am »
Any updates on this? How do I get a build with this feature?

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #8 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).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #9 on: April 22, 2020, 02:35:53 pm »
For another time, please don't bump all threads related to your specific situation. ;)

As mentioned I'm slowly working on updating the mentioned PR: https://github.com/SFML/SFML/pull/1235
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Scancodes (Windows, Linux, Mac testing needed)
« Reply #10 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  :( .