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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - XianForce

Pages: [1]
1
Window / [SFML 1.6]Not Getting KeyPressed events?
« on: November 20, 2011, 02:30:40 am »
So, I usually wouldn't resurrect a topic this old, but my problem is still the same, but I have more information :).

So the problem seems to be when I pass an sf::Event reference to a function. When I take care of the event locally, everything is fine, but once I pass that reference to another function, things get a little weird.

I do not get key press events for any letters, numbers, symbols, spaces/carriage returns, or the escape key. Every other key (F1-F12, Ctrl, Alt, Delete, Arrow Keys, etc.) still work with key press, though.

Before you tell me to make a stripped down example, I did and here it is :) :

Code: [Select]


#include <SFML/Window.hpp>
#include <iostream>

bool HandleEvents(sf::Event& event)
{
    if(event.Type == sf::Event::Closed)
    {
        return false;
    }

    if(event.Type == sf::Event::KeyPressed)
    {
        return false;
    }

    return true;
}

int main()
{
    sf::Window* window = new sf::Window(sf::VideoMode(600, 800, 32), "Test");
    sf::Event event;
    bool running = true;

    while(running)
    {
        while(window->GetEvent(event))
        {
            running = HandleEvents(event);
        }
    }

    return 0;
}


Same problem persists between the two. I didn't see any issue with KeyRelease, only KeyPress... So, help please :D?

2
Window / [SFML 1.6]Not Getting KeyPressed events?
« on: April 20, 2011, 11:51:45 pm »
Quote from: "Laurent"
If it works in the SFML examples, then there's something wrong in your code. Try to reduce it to something minimal, the error should become obvious.


I've reduced it to as small as I really can, and I see nothing. I don't mean to be a bother though :o.

But, I have a simple event loop:

Code: [Select]

while(Core::mp_Window->GetEvent(Event));
{
       if(mp_GlobalState)
       {
           mp_GlobalState->OnEvent(Event);
       }
}


Then in the OnEvent method for global state I have:

Code: [Select]

if(event.Type == sf::Event::Closed)
    {
        mi_ReturnCode = 0;
    }

    else if((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
    {
        mi_ReturnCode = 0;
    }


Setting the ReturnCode to anything other than 1 will cause the program to end, yet pressing Escape doesn't work in this. But when I change it to KeyReleased, it does work...

Events are literally not referenced anywhere else in code...

3
Window / [SFML 1.6]Not Getting KeyPressed events?
« on: April 19, 2011, 08:49:41 am »
Quote from: "Laurent"
Have you tried the samples included in the SFML SDK? Pong and PostFx, for example, use the KeyPressed event.


Yeah, those do work, both as the included executables, and when I compiled them myself.

Also, that line that I write out to verify that an event occurred, is written a seemingly infinite number of times. The only other relevant code for that issue would be:

Code: [Select]

for(it = eventComponents.begin(); it != eventComponents.end(); ++it)
    {
        //check if data is allocated...
        if(it->second)
        {
            //Call the event callback for each event component... Looks a bit confusing because
            //the functoid has to be dereferenced to call the () operator.
            (*((it->second)->mp_EventCallback))(event);
        }
    }


It's from an object that manages all the event components; it iterates through each one when an event occurs, and the event is passed to it.

So the event occurs, and it's then passed to the current state, which passes it to this object, which then passes it to each component... But I only have one component in this example...

4
Window / [SFML 1.6]Not Getting KeyPressed events?
« on: April 19, 2011, 01:30:21 am »
I've been using SFML for about a month now (switched over from SDL, want to get some hardware acceleration before I jump into OpenGL), and I've been implementing a component entity system.

Well, I got everything set up for events, but I've noticed that I'm not receiving key press events. I get every other event, I even set up a quick switch statement to check every other event (well, outside of joystick events...), but the only one I don't get is key presses, any idea on why that is?

Here's the code that's relevant:

Code: [Select]

//Events are split between a current and global state like this:
while(Core::mp_Window->GetEvent(Event));
        {
            if(Event.Type == sf::Event::Closed ||
                Event.Type == sf::Event::Resized ||
                Event.Type == sf::Event::LostFocus ||
                Event.Type == sf::Event::GainedFocus)
            {
                if(mp_GlobalState)
                {
                    mp_GlobalState->OnEvent(Event);
                }
            }

            else
            {
                if(mp_CurrentState)
                {
                    mp_CurrentState->OnEvent(Event);
                }
            }
        }

//In a test event functoid...
bool TestFunc::operator()(sf::Event& event)
{
    switch(event.Type)
    {
        case sf::Event::KeyPressed:
            std::cout << "KeyPressed" << std::endl;
            break;
        case sf::Event::KeyReleased:
            std::cout << "KeyReleased" << std::endl;
            break;
        case sf::Event::MouseWheelMoved:
            std::cout << "MouseWheelMoved" << std::endl;
            break;
        case sf::Event::MouseButtonPressed:
            std::cout << "MouseButtonPressed" << std::endl;
            break;
        case sf::Event::MouseButtonReleased:
            std::cout << "MouseButtonReleased" << std::endl;
            break;
        case sf::Event::MouseMoved:
            std::cout << "MouseMoved" << std::endl;
            break;
        default:
            break;
    }


    return true;
}



All the events passed to the global state work correctly, and I've tested all the events, but the only one that I don't get a response from is KeyPressed...

EDIT: I'm using SFML 1.6, Code::Blocks (MinGW), on Windows

Pages: [1]
anything