//============================================================================== bool KeyPressMappingSet::keyPressed (const KeyPress& key, Component* originatingComponent) { bool used = false; const CommandID commandID = findCommandForKeyPress (key); const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID); if (ci != 0 && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0) { ApplicationCommandInfo info (0); if (commandManager->getTargetForCommand (commandID, info) != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0) { invokeCommand (commandID, key, true, 0, originatingComponent); used = true; } else { if (originatingComponent != 0) originatingComponent->getLookAndFeel().playAlertSound(); } } return used; }
void Device::mqttData(void* response) { RESPONSE res(response); LOG("Received: topic="); String topic = res.popString(); LOG(topic.c_str()); LOG("data="); String data = res.popString(); LOG(data.c_str()); uint8_t start = topic.indexOf("asset/") + 6; uint8_t end = topic.lastIndexOf("/command"); String name = topic.substring(start, end); Command cmd(name, data); // echo back command to platform to confirm the receipt if (_autoEcho) send(name.c_str(), data.c_str()); // invoke user callback, if set invokeCommand(cmd); }
void CommandHandler::handleCommand(const std::string &command, ChatTab *const tab) { const size_t pos = command.find(' '); const std::string type(command, 0, pos); std::string args(command, pos == std::string::npos ? command.size() : pos + 1); args = trim(args); invokeCommand(type, args, tab, true); }
void CommandRegistry::slotInvokeCommand() { const QObject *s = sender(); QString actionName = s->objectName(); if (m_builders.find(actionName) == m_builders.end()) { std::cerr << "CommandRegistry::slotInvokeCommand: Unknown actionName \"" << qStrToStrLocal8(actionName) << "\"" << std::endl; return; } invokeCommand(actionName); }
//============================================================================== bool KeyPressMappingSet::keyPressed (const KeyPress& key, Component* originatingComponent) { bool commandWasDisabled = false; for (int i = 0; i < mappings.size(); ++i) { CommandMapping* const cm = mappings.getUnchecked(i); if (cm->keypresses.contains (key)) { const ApplicationCommandInfo* const ci = commandManager->getCommandForID (cm->commandID); if (ci != nullptr && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0) { ApplicationCommandInfo info (0); if (commandManager->getTargetForCommand (cm->commandID, info) != 0) { if ((info.flags & ApplicationCommandInfo::isDisabled) == 0) { invokeCommand (cm->commandID, key, true, 0, originatingComponent); return true; } else { commandWasDisabled = true; } } } } } if (originatingComponent != nullptr && commandWasDisabled) originatingComponent->getLookAndFeel().playAlertSound(); return false; }
bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent) { bool used = false; const uint32 now = Time::getMillisecondCounter(); for (int i = mappings.size(); --i >= 0;) { CommandMapping* const cm = mappings.getUnchecked(i); if (cm->wantsKeyUpDownCallbacks) { for (int j = cm->keypresses.size(); --j >= 0;) { const KeyPress key (cm->keypresses.getReference (j)); const bool isDown = key.isCurrentlyDown(); int keyPressEntryIndex = 0; bool wasDown = false; for (int k = keysDown.size(); --k >= 0;) { if (key == keysDown.getUnchecked(k)->key) { keyPressEntryIndex = k; wasDown = true; used = true; break; } } if (isDown != wasDown) { int millisecs = 0; if (isDown) { KeyPressTime* const k = new KeyPressTime(); k->key = key; k->timeWhenPressed = now; keysDown.add (k); } else { const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed; if (now > pressTime) millisecs = (int) (now - pressTime); keysDown.remove (keyPressEntryIndex); } invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent); used = true; } } } } return used; }