KeyRelease事件未在全屏模式下触发

时间:2013-09-14 14:08:46

标签: c++ macos sfml

就像标题所说的那样,在Mac OS X上全屏模式下根本没有触发KeyRelease个事件(未测试Linux / Windows,也可能会被破坏)。

以下是代码:

sf::ContextSettings settings;
settings.antialiasingLevel = 8;

sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "My Game", sf::Style::Fullscreen, settings);
window.setFramerateLimit(60);
window.setVerticalSyncEnabled(true);
window.setMouseCursorVisible(false);

while (window.isOpen())
{

    while (window.pollEvent(event))
    {
        // Close window : exit
        if (event.type == sf::Event::Closed) {
            window.close();
        }

        if (event.type == sf::Event::KeyPressed) {
                switch (event.key.code) {
                    case sf::Keyboard::Escape: // Escape pressed : exit
                        window.close();
                        break;
                    default:
                        game->handleKeyCode(event.key.code);
                        break;
                }

        } else if(event.type == sf::Event::KeyReleased) {
                printf("KeyRelease Fired!\n");
        }
    }
}

如果我不使用全屏模式,而是像这样初始化window,那么KeyRelease事件就可以了:

sf::RenderWindow window(sf::VideoMode(1400, 950), "My Game", sf::Style::Default, settings);

1 个答案:

答案 0 :(得分:1)

recent commit解决此问题。从它的git编译SFML应该可以解决这个问题。有关编译的更多详细信息,请参阅the official tutorial