就像标题所说的那样,在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);