//============================================================================== bool CodeEditorComponent::keyPressed (const KeyPress& key) { if (! TextEditorKeyMapper<CodeEditorComponent>::invokeKeyFunction (*this, key)) { if (key == KeyPress::tabKey || key.getTextCharacter() == '\t') { insertTabAtCaret(); } else if (key == KeyPress::returnKey) { newTransaction(); insertTextAtCaret (document.getNewLineCharacters()); } else if (key.isKeyCode (KeyPress::escapeKey)) { newTransaction(); } else if (key.getTextCharacter() >= ' ') { insertTextAtCaret (String::charToString (key.getTextCharacter())); } else { return false; } } return true; }
//============================================================================== bool CodeEditorComponent::keyPressed (const KeyPress& key) { if (! TextEditorKeyMapper<CodeEditorComponent>::invokeKeyFunction (*this, key)) { if (key == KeyPress::tabKey || key.getTextCharacter() == '\t') handleTabKey(); else if (key == KeyPress::returnKey) handleReturnKey(); else if (key == KeyPress::escapeKey) handleEscapeKey(); else if (key == KeyPress ('[', ModifierKeys::commandModifier, 0)) unindentSelection(); else if (key == KeyPress (']', ModifierKeys::commandModifier, 0)) indentSelection(); else if (key.getTextCharacter() >= ' ') insertTextAtCaret (String::charToString (key.getTextCharacter())); else return false; } pimpl->handleUpdateNowIfNeeded(); return true; }
// Component::keyPressed ( const KeyPress & key ) bool NumberBox::keyPressed(const KeyPress & key) { // Bouml preserved body begin 0004868D if(String("0123456789.,-+").indexOfChar(key.getTextCharacter()) > -1 || key == KeyPress::returnKey || key.isKeyCode (KeyPress::escapeKey) ) { TextEditor::keyPressed(key); } return false; // Bouml preserved body end 0004868D }
bool MainContentComponent::keyPressed(const KeyPress& key) { switch (key.getTextCharacter()) { case 'w': Copter->setBounds(xpos,ypos-=8,/*getWidth()*0.3,getHeight()*0.3*/80,60); return true; break; case 's': Copter->setBounds(xpos,ypos+=5,/*getWidth()*0.3,getHeight()*0.3*/80,60); return true; break; } return false; }
void KeyPressMappingSet::addKeyPress (const CommandID commandID, const KeyPress& newKeyPress, int insertIndex) { // If you specify an upper-case letter but no shift key, how is the user supposed to press it!? // Stick to lower-case letters when defining a keypress, to avoid ambiguity. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter()) && ! newKeyPress.getModifiers().isShiftDown())); if (findCommandForKeyPress (newKeyPress) != commandID) { if (newKeyPress.isValid()) { for (int i = mappings.size(); --i >= 0;) { if (mappings.getUnchecked(i)->commandID == commandID) { mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress); sendChangeMessage(); return; } } if (const ApplicationCommandInfo* const ci = commandManager.getCommandForID (commandID)) { CommandMapping* const cm = new CommandMapping(); cm->commandID = commandID; cm->keypresses.add (newKeyPress); cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0; mappings.add (cm); sendChangeMessage(); } else { // If you hit this, you're trying to attach a keypress to a command ID that // doesn't exist, so the key is not being attached. jassertfalse; } } } }
bool TextBuffer::keyPressed (const KeyPress& key) { //std::cout << "keyPressed: " << key.getTextDescription().toUTF8() << T("\n"); if (isMatching()) stopMatching(); TextEditor::keyPressed(key); juce_wchar chr=key.getTextCharacter(); CommandID com=CommandIDs::EditorTextChanged; if (key.getKeyCode()==KeyPress::returnKey) com=CommandIDs::EditorNewline; else if (key.getKeyCode()==KeyPress::backspaceKey) com=CommandIDs::EditorBackspace; else if (!testFlag(EditFlags::MatchingOff) && (chr==')' || ((textid==TextIDs::Sal) && chr=='}') || ((textid==TextIDs::Sal2) && chr=='}'))) matchParens(); colorizeAfterChange(com); setFlag(EditFlags::NeedsSave); return true; }
//============================================================================== bool CodeEditorComponent::keyPressed (const KeyPress& key) { const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown(); const bool shiftDown = key.getModifiers().isShiftDown(); if (key.isKeyCode (KeyPress::leftKey)) { cursorLeft (moveInWholeWordSteps, shiftDown); } else if (key.isKeyCode (KeyPress::rightKey)) { cursorRight (moveInWholeWordSteps, shiftDown); } else if (key.isKeyCode (KeyPress::upKey)) { if (key.getModifiers().isCtrlDown() && ! shiftDown) scrollDown(); #if JUCE_MAC else if (key.getModifiers().isCommandDown()) goToStartOfDocument (shiftDown); #endif else cursorUp (shiftDown); } else if (key.isKeyCode (KeyPress::downKey)) { if (key.getModifiers().isCtrlDown() && ! shiftDown) scrollUp(); #if JUCE_MAC else if (key.getModifiers().isCommandDown()) goToEndOfDocument (shiftDown); #endif else cursorDown (shiftDown); } else if (key.isKeyCode (KeyPress::pageDownKey)) { pageDown (shiftDown); } else if (key.isKeyCode (KeyPress::pageUpKey)) { pageUp (shiftDown); } else if (key.isKeyCode (KeyPress::homeKey)) { if (moveInWholeWordSteps) goToStartOfDocument (shiftDown); else goToStartOfLine (shiftDown); } else if (key.isKeyCode (KeyPress::endKey)) { if (moveInWholeWordSteps) goToEndOfDocument (shiftDown); else goToEndOfLine (shiftDown); } else if (key.isKeyCode (KeyPress::backspaceKey)) { backspace (moveInWholeWordSteps); } else if (key.isKeyCode (KeyPress::deleteKey)) { deleteForward (moveInWholeWordSteps); } else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)) { copy(); } else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0)) { copyThenCut(); } else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)) { paste(); } else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0)) { undo(); } else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0) || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0)) { redo(); } else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0)) { selectAll(); } else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t') { insertTabAtCaret(); } else if (key == KeyPress::returnKey) { newTransaction(); insertTextAtCaret (document.getNewLineCharacters()); } else if (key.isKeyCode (KeyPress::escapeKey)) { newTransaction(); } else if (key.getTextCharacter() >= ' ') { insertTextAtCaret (String::charToString (key.getTextCharacter())); } else { return false; } return true; }