New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scancode #1235
Scancode #1235
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned, it's still missing Windows and Linux (& iOS and Android) implementations.
We're still looking for someone to be willing to provide an implementation for Windows and Linux! If you want to contribute, fork SFML and provide a pull request based this branch feature/scancode. |
681e0b2
to
f6d95ce
Compare
I think the scancodes should be named more similar to the SFML key codes already. For example, since Return is used in the key code enum, it should be used for the scan code on the main key set. However, the number pad's enter key should probably never be called return. The current setup seems inverted. If the pad's enter isto be called Return, it could be NumpadReturn or similar, which would mean that PadEquals should be NumpadEquals. Whether it is Numpad or just Pad, they should be the same. It's also possible that the pad's Enter key on PC is equivalent to the pad's Equals key on the Mac. There is absolutely no need for the unnecessary pre-fix 'forwards' to be added to a standard slash. 'Reverse solidus' just means "backwards slash"; how is it different from BackSlash? All of the above presumes the Scan prefix is included, of course. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, since Return is used in the key code enum, it should be used for the scan code on the main key set. However, the number pad's enter key should probably never be called return. The current setup seems inverted.
Yes, there are some inconsistencies. The names I've selected are from the USB HID specs. We might indeed want to deviate from them a bit here and there.
'Reverse solidus' just means "backwards slash"; how is it different from BackSlash?
That's a good question, to which the HID specs doesn't seem to give an answer, so I don't know.
@SFML/sfml I'd like to update this but I need your feedback on the above open questions. |
By the way, I've been working on Linux implementation for some time, and I'll make a pull request once all the functions are implemented. I think there'll be a lot of things to discuss since the current keyboard code for X11 was a bit scattered around and I had to move it around a bit to get the needed functionality. I based my implementation on GLFW's, because scancodes on X11 are not easy to deal with. P.S. |
https://github.com/eliasdaler/SFML/tree/scancode-linux |
This PR is now stalled until #1395 is merged in order to address naming. @eliasdaler I only see your question now... I guess it's always safer to post an additional comment instead of editing your messages. ;-)
That would be perfect IMO. Did you make some progress on |
ce05059
to
7216429
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A feature of this size can't get proper testing until it's actually merged and in the hands of those using the 2.6.x branch. I move to merge this PR now and fix the remaining issues in subsequent PRs leading up to the release of 2.6.0. That will result in us more quickly developing a shippable implementation of scancodes than keeping it quarantined in this branch forever.
I agree with @ChrisThrasher You can release a version 2.6.0, and do fixes in 2.6.1. If necessary, quickly release 2.6.1 after 2.6.0. 2.6 update is huge, and many of the errors will only show up by releasing it. |
53e14db
to
d4a4903
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor clean ups
d4a4903
to
84e734c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What can I say? It's been in the making for a long time and there's still work to be done (e.g. DRM support), but it's time to get it into the hands of all the 2.6.x
branch users and I guess after quite some clean up work into the master
branch users. 🎉
Thank you to everyone who have contributed to this feature! Special thanks to @mantognini for the macOS part, @JonnyPtn for the Windows part, @eliasdaler for the Linux part, and @kimci86 for all the testing and fixing. <3 |
This is awesome, kudos to all of you! 🎉 |
I've had some opportunity to do some testing of this and I've found that it's working 'almost' perfectly. Some tiny issues that I've found (on my keyboard, at least):
I've found no other issues in usage so great job! It's worth noting that it's very common for right alt (when named Alt Gr) to trigger a left control event and a simple search shows that this happens a lot. I presume the function key won't get noticed as it's designed to be used in conjunction with other keys. |
Thank you for testing this! 🙂
This is usually a "hardware" switch and doesn't get reported, and there isn't really a scancode for it as far as I know.
Yeah, it's a rather special key and all implementations I've seen, have some workarounds for it. I didn't really feel like investing more time just to figure a perfect solution. If someone wants to spend a bit of time investigating, I'd be more than happy to merge such a PR.
Alt Gr is not the same as RAlt, but I understand your point about physical keys being pressed. Not sure if SFML should filter the event here 🤔 |
Thanks for replying.
Glad you like it :) As expected with the function key. Mainly just wanted to state it so that we're aware if anyone brings it up saying that "it doesn't work". Print screen is always a weird key. That said, SFML is providing a code (value) for it; does it work in some cases?
I agree that Alt Gr is not the same as R Alt. However, the physical key is there instead of it, in the same way a \ key might be there instead of < key, for instance. |
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:
Snapshot Builds: https://artifacts.sfml-dev.org/by-branch/feature/scancode/
SFML Tasks
Description (Names)-> OS & Language dependantWindows: Look into issue with TDM build-> TDM builds were decommissionedsf::Keyboard::Key
names for Numpad to align with scancode naming?0x56
Layout agnostic keyboard reference image from the Microsoft Scancode Specification
Following on #7, and some (old) discussion on the forum, here is an API to deal with Scancodes and an implementation for Mac. You can test this implementation, or new ones, using the scancode branch of SFML-Test-Events.
Note that there are a few TODOs that deserve a quick discussion, especially w.r.t. the upcoming 3.0 and its breaking changes.
So, send your feedback this way and if you want to implement it for Linux or Windows, let me know!