garrynewman / GWEN

Abandoned: GWEN - GUI Without Extravagant Nonsense.
MIT License
427 stars 102 forks source link

SFML2 copy and paste bug #63

Closed Wizzard033 closed 11 years ago

Wizzard033 commented 11 years ago

There is a bug with SFML2 input that makes copy and paste not work. The following fix goes in include/Gwen/Input/SFML.h:

                        case sf::Event::KeyPressed:
                        case sf::Event::KeyReleased:
                            {
#if SFML_VERSION_MAJOR == 2
                                bool bPressed = ( event.type == sf::Event::KeyPressed );
                                char keyCode = event.key.code + 97;
                                bool control = event.key.control;

                                if ( control && bPressed && keyCode >= 'a' && keyCode <= 'z' )
                                {
                                    return m_Canvas->InputCharacter( keyCode );
                                }

                                unsigned char iKey = TranslateKeyCode( event.key.code );
#else
                                bool bPressed = ( event.Type == sf::Event::KeyPressed );
                                char keyCode = event.Key.Code;
                                bool control = event.Key.Control;

                                if ( control && bPressed && keyCode >= 'a' && keyCode <= 'z' )
                                {
                                    return m_Canvas->InputCharacter( keyCode );
                                }

                                unsigned char iKey = TranslateKeyCode( keyCode );
#endif

                                return m_Canvas->InputKey( iKey, bPressed );
                            }

Note the keyCode conversion (adding 97) that turns the event.key.code into an ASCII character.