#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
int main(){
sf::RenderWindow window(sf::VideoMode(640, 480), "Window");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close(); break;
case sf::Event::KeyPressed:
std::cout << event.key.code;
break;
}
}
}
return 0;
}
我收到一堆这样的警告 enumeration value 'MouseLeft' not handled in switch
我尝试将其放在if
声明中而不是switch
摆脱警告的语句中,但仍然不会输出event.key.code
,只有当我将其放在pollevent(event)
循环之外但无法拾取字母时,我才能使其正常工作。
<< std::flush;
在cout
s后面添加一个,您将看到密钥代码。否则,直到离开SFML主循环时才打印它们(不是在中断时而是在使用x按钮正常关闭时)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句