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

Author Topic: TextEntered gives me mouse input. Is that intentional?  (Read 2390 times)

0 Members and 1 Guest are viewing this topic.

Hork

  • Newbie
  • *
  • Posts: 2
    • View Profile
TextEntered gives me mouse input. Is that intentional?
« on: January 28, 2017, 12:01:31 pm »
Hi there,

i just started to mess around with keyboard input. And i try to figure out a nice and clean way to get keyboardinput for some sort of typing game.

So i figured out how to filter the input a bit and how to get the inputs in need. But the problem i get is, that my mouse also produces keyboard input. These appear to be pretty random.
But the interesting thing is, that only produces input, when the mouse is on the left quarter of the SFML window.

I'm confused and not sure if this intentional. Any ideas?
Also: Do you think 'textentered' is the best solution when i need keyboardinput key by key for a typing game?

Here is the complete code i'm experimenting with:
#include <iostream>
#include "SFML\Graphics.hpp"


int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();

                        if (sf::Event::TextEntered)
                        {
                                if (event.text.unicode >= 32 && event.text.unicode <= 128)
                                {
                                        std::cout << "ASCII character typed: " << static_cast<char>(event.text.unicode) << std::endl;
                                }                      
                        }
                }

                window.clear();
                window.display();
        }

        return 0;
}

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: TextEntered gives me mouse input. Is that intentional?
« Reply #1 on: January 28, 2017, 12:05:48 pm »
if (sf::Event::TextEntered)
 

should be

if (event.type == sf::Event::TextEntered)
 

sf::Event::TextEntered is an enum whose value is almost certainly not 0, therefore will always return true

Hork

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: TextEntered gives me mouse input. Is that intentional?
« Reply #2 on: January 28, 2017, 12:19:09 pm »
Oh, thank you!
I focused so much on the mouse thing, that i thought i just missunderstood the textentered event.

 

anything