Hey there.
I'm currently working on a little game project to gather more experience with C++ and SFML.
Now I came across a kinda odd problem while making a visual keyboard for entering a character name.
If I'm using sf::event to check for keypresses ->
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Right)
{
}
It works fine for the arrow keys, to move around the marker to select whatever key on the visual keyboard you want to use. But just below that, when I used the same thing to check if the 'Enter' key got pressed, it didn't work.
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Enter)
{
}
After much trying around and looking for solutions, I noticed that for some reason, it only recognizes that 'Enter' key input when I'm holding alt while pressing Enter. Further trying out showed that this applies to most other keys, it only recognizes letter presses (like "N" or "L") or Spacebar if I'm holding alt at the same time. Yet the arrow keys work fine without holding Alt, with the exact same code.
Also, my current now working solution to it - simply using "sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)", does work without the odd issue of having to hold 'Alt'.
So.. I do have a solution to my problem, but I still want to understand why it is causing that weird behavior when using event to check for the key inputs. While trying to figure it out, at one point I used the following code to check what the pressed key is recognized as by outputting it to the console:
std::cout << "Pressed button: " << event.key.code << "\n";
Oddly, it output the press of 'Enter' as '13'. Pressing alt + 'Enter' returned '58' which should be the correct value for the key.
Does anyone have an idea what could be causing this?
I figured I'll only put the relevant code here, but if you need I can post all of it.
Though I think I pretty much narrowed the issue down to that one question -
What could cause sf::event require 'alt' being held to recognize 'Enter' correctly, while arrow keys are recognized normally and sf::keyboard also recognizes 'Enter' normally?
(and no, there's nothing in my code doing anything with the 'alt' key or checking for it)