鼠标和键盘总是有输入,尽管我什么都不做

Mouse and keyboard always get input althoughtI don't do anything

我正在使用 SFML 库编写游戏代码。当我按下键并单击鼠标时,我有一些代码要做

我用这个: Sf::keyBoard::isKeyPressed 还有这个: Sf::Mouse::isButtonPressed

但不知何故,尽管我没有点击或按下任何东西,但每一帧总是有代码 运行。

是我的电脑有问题还是别的什么?

你能这样试试吗?

    while (window.isOpen())
    {
        sf::Event event;

        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
            {
                _isGameNotStarted = false;
            }
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            {
                p->playerMoveR(_isGameNotStarted);
            }
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
                p->playerMoveL(_isGameNotStarted);
            }
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
            {
                if (_isGameFinished == true)
                    resetLevel();
            }
        }
    }