bool CKey::TestKey(unsigned int key) { if (key == KEY(PAUSE) || key == KEY(PRINT)) return true; // blocked key for (int i = 0; i < INPUT_SLOT_MAX; i++) { InputSlot slot = static_cast<InputSlot>(i); InputBinding b = m_robotMain->GetInputBinding(slot); if (key == b.primary || key == b.secondary) m_robotMain->SetInputBinding(slot, InputBinding()); // nothing! if (b.primary == KEY_INVALID) // first free option? m_robotMain->SetInputBinding(slot, InputBinding(b.secondary, b.primary)); // shift } return false; // not used }
void ControlsScene::update() { if ( changing and newControlEvents.size() > 0 ) { for ( std::size_t i = 0; i < newControlEvents.size(); ++i ) { sf::Event event = newControlEvents[ i ]; if ( event.type == sf::Event::MouseButtonPressed ) { ( * changing->first ) = InputBinding( event.mouseButton.button ); } else if ( event.type == sf::Event::KeyPressed ) { ( * changing->first ) = InputBinding( event.key.code ); } else if ( event.type == sf::Event::JoystickMoved ) { ( * changing->first ) = InputBinding( event.joystickMove.joystickId, event.joystickMove.axis, static_cast< int >( event.joystickMove.position / std::abs( event.joystickMove.position ) ) ); } else if ( event.type == sf::Event::JoystickButtonPressed ) { ( * changing->first ) = InputBinding( event.joystickButton.joystickId, event.joystickButton.button ); } } std::size_t index = 0; if ( sf::Keyboard::isKeyPressed( sf::Keyboard::LShift ) or sf::Keyboard::isKeyPressed( sf::Keyboard::RShift ) ) ++index; if ( sf::Keyboard::isKeyPressed( sf::Keyboard::LControl ) or sf::Keyboard::isKeyPressed( sf::Keyboard::RControl ) ) ++index; if ( index < newControlEvents.size() ) { sf::Event event = newControlEvents[ index ]; if ( event.type == sf::Event::MouseButtonPressed ) { ( * changing->first ) = InputBinding( event.mouseButton.button ); } else if ( event.type == sf::Event::KeyPressed ) { ( * changing->first ) = InputBinding( event.key.code ); } else if ( event.type == sf::Event::JoystickMoved ) { ( * changing->first ) = InputBinding( event.joystickMove.joystickId, event.joystickMove.axis, static_cast< int >( event.joystickMove.position / std::abs( event.joystickMove.position ) ) ); } else if ( event.type == sf::Event::JoystickButtonPressed ) { ( * changing->first ) = InputBinding( event.joystickButton.joystickId, event.joystickButton.button ); } updateControls(); changing = NULL; } newControlEvents.clear(); } }