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

Author Topic: Scancodes - Round 2  (Read 20570 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Scancodes - Round 2
« on: May 27, 2021, 02:01:24 pm »
Scancodes is the last (major) feature which is required by the Roadmap planning to complete SFML 2.6

We have already done a Round 1 of reviewing and testing with different branches and still some misalignments.
After quite some additional work and great documentation efforts, I believe the code base is close to finalization and we'd like to invite everyone to help review and test our Scancodes implementation.

Code & PR: https://github.com/SFML/SFML/pull/1235
Snapshot Builds: https://artifacts.sfml-dev.org/by-branch/feature/scancode/

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

Either of the follow applications can be used to test:

The Scancode names and documentation description are generally in reference to the AT-101 layout, as for example seen on the following image:


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 AT-101 reference layout. Key description should depend on your layout and produce the same thing that you see when you type into a text editor
  • Toggle 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

New API

  • Enum sf::Keyboard::Scancode
  • On key events: sf::Keyboard::Scancode scancode
  • static bool sf::Keyboard::isKeyPressed(sf::Keyboard::Scancode)
  • static sf::Keyboard::Key localize(sf::Keyboard::Scancode code)
  • static sf::Keyboard::Scancode unlocalize(sf::Keyboard::Key key)
  • static sf::String getDescription(sf::Keyboard::Scancode code)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/