KeyEvent FifechanManager::translateKeyEvent(const fcn::KeyEvent& fcnevt) { KeyEvent keyevt; if(fcnevt.getType() == fcn::KeyEvent::Pressed) keyevt.setType(KeyEvent::PRESSED); else if(fcnevt.getType() == fcn::KeyEvent::Released) keyevt.setType(KeyEvent::RELEASED); else { FL_WARN(_log, LMsg("FifechanManager::translateKeyEvent() - ") << "Unknown event type: " << fcnevt.getType()); keyevt.setType(KeyEvent::UNKNOWN); } keyevt.setShiftPressed(fcnevt.isShiftPressed()); keyevt.setControlPressed(fcnevt.isControlPressed()); keyevt.setAltPressed(fcnevt.isAltPressed()); keyevt.setMetaPressed(fcnevt.isMetaPressed()); keyevt.setNumericPad(fcnevt.isNumericPad()); // Convert from fifechan keyval to FIFE keyval int32_t keyval = fcnevt.getKey().getValue(); keyval = convertFifechanKeyToFifeKey(keyval); keyevt.setKey(Key(static_cast<Key::KeyType>(keyval), keyval)); return keyevt; }
void CommandLine::keyPressed(fcn::KeyEvent &keyEvent) { fcn::Key key = keyEvent.getKey(); int32_t keyType = key.getValue(); if (keyType == Key::Left && getCaretPosition() > 0) { TextField::keyPressed(keyEvent); } else if (keyType == Key::Right && getCaretPosition() < getText().size()) { TextField::keyPressed(keyEvent); } else if (keyType == Key::Down && !m_history.empty()) { if( m_history_position < m_history.size() ) { if( ++m_history_position == m_history.size() ) { setText( m_cmdline ); } else { setText( m_history[m_history_position] ); } }; } else if (keyType == Key::Up && !m_history.empty()) { if( m_history_position > 0 ) { if( m_history_position == m_history.size() ) { m_cmdline = getText(); } --m_history_position; setText( m_history[m_history_position] ); }; } else if (keyType == Key::Delete && getCaretPosition() < getText().size()) { TextField::keyPressed(keyEvent); } else if (keyType == Key::Backspace && getCaretPosition() > 0) { TextField::keyPressed(keyEvent); } else if (keyType == Key::Enter) { if( getText() != "" ) { if(m_callback) { m_callback( getText() ); } m_history.push_back( getText() ); m_history_position = m_history.size(); setText(""); } } else if (keyType == Key::Home) { setCaretPosition(0); } else if (keyType == Key::End) { setCaretPosition(getText().size()); } else if (key.isCharacter() || static_cast<uint32_t>(key.getValue()) > 255) { TextField::keyPressed(keyEvent); } stopBlinking(); fixScroll(); }