正如标题所说,KeyRelease
在 Mac OS X 上的全屏模式下根本不会触发事件(尚未测试 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);