SFML community forums

Help => Window => Topic started by: sfml_noob on November 17, 2020, 06:56:13 pm

Title: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: sfml_noob on November 17, 2020, 06:56:13 pm
Hi!
I'm following the book "Beginning C++ Game Programming" from John Horton.
One of the first project uses the Enter key:

// Start the game
if (Keyboard::isKeyPressed(Keyboard::Enter))
{
...
}
It's working with the central Enter key, but I'm surprised that pressing the right Enter key (the one with the numpad) does nothing.
Is it possible to get the Numpad Enter key working?
Thanks!
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: Stauricus on November 17, 2020, 07:47:03 pm
well, that's rather strange. I was going to say that Keyboard::Enter references only the main key (Return), but I just went to the docs to search which would be the key to numpad enter and there is no mention to it. as the docs mention "Enter | The Enter/Return keys", with an "s", I'm guessing that it could be a bug  ???
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: fallahn on November 17, 2020, 09:47:49 pm
I've tested this, and it works for me. I'm using Visual Studio 2019 with the latest revision of SFML. Can you share which platform you're using (OS/compiler etc) so other people can try and reproduce the problem? Also, what's your keyboard layout?
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: sfml_noob on November 18, 2020, 07:55:42 am
Thanks for the reply!
I'm on Arch linux. The compiler is g++ 10.2.0.
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: eXpl0it3r on November 18, 2020, 08:31:36 am
Looks like we only handle XK_Return (https://github.com/SFML/SFML/blob/master/src/SFML/Window/Unix/InputImpl.cpp#L69) and not XK_KP_Enter on Linux.
While on Windows, I think the VK_RETURN (https://github.com/SFML/SFML/blob/master/src/SFML/Window/Win32/InputImpl.cpp#L110) applies for both the regular enter key and the numpad enter key.

Maybe there's a setting somewhere to change this behavior?
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: sfml_noob on November 18, 2020, 09:08:06 am
I've found a thread about this problem (unrelated to SFML: it's "Juce", a cross-platform music software).
Maybe it can help...
https://forum.juce.com/t/keypad-enter-key-doesnt-work-like-enter-key/10965/3
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: sfml_noob on November 19, 2020, 02:59:37 pm
I'm more advanced in the book. Now I've found that with another method, both Enter keys are detected!

 
while (window.pollEvent(event))
         {
                if (event.type == Event::KeyPressed)
               {
                    // Pause a game while playing
                    if (event.key.code == Keyboard::Return && state == State::PLAYING)
                    {
                        state = State::PAUSED;
                }
 
Title: Re: Enter key from Numpad not working (contrary to "main" Enter key)
Post by: eXpl0it3r on November 20, 2020, 10:08:29 am
We do handle XK_KP_Enter (https://github.com/SFML/SFML/blob/master/src/SFML/Window/Unix/WindowImplX11.cpp#L392) for events, but not for the isKeyPressed one.

Not sure if we can easily fix this, because the isKeyPressed is a mapping from sf::Keyboard::Key to symKey, while the event is a mapping from symKey to sf::Keyboard::Key, so for the latter we can assign multiple symKeys to the same SFML key code.

I guess this will be solved with scan codes that differentiate between numpad enter and normal enter.