////////////////////////////////////////////////////////////////////////////// /// /// Send result to output /// ////////////////////////////////////////////////////////////////////////////// void controller::sendResult(long data) { if (GetVerbose()) SpacePrint("Result:%d\n", data); int i; unsigned long power; unsigned int digit; // Negative number if (data < 0) { sendCharacter('-'); data *= -1; } for(i=getOrder(data);i>=0;i--) { power = pow(10, i); digit = data/power; data -= digit*power; sendCharacter(itoa(digit)); } sendCharacter(0xD); }
////////////////////////////////////////////////////////////////////////////// /// /// Display message /// ////////////////////////////////////////////////////////////////////////////// void controller::displayMessage(char* message) { int i = 0; do { sendCharacter(message[i]); } while (!isLF(message[i++])); sendCharacter(0xD); }
int sendOrder(HANDLE hSerial, char order[20]) { printf("\n%s\n",order); // output to be sure the right order has been sent. int ch[2], nr=0; // Sometimes - e.g. in debug mode - the PID // doesn't get the request for communication. // Therefore this loop: while(ch[0]!='A'){ sendCharacter(hSerial,"*"); ch[0]=sendReceiveCharacter(hSerial,"A"); nr++; } ch[0]=sendReceiveCharacter(hSerial,"_"); // Usually the PID echoes the sent character. // If the while loop ahead runs often, there seems // to be some kind of queue of 'A's somewhere - // maybe the PID is still echoing or there is // is some buffer related stuff I don't understand. // // Here comes my workaround: int tmp=0; while(tmp<=nr && ch[0]!='_'){ ch[0]=receiveCharacter(hSerial); tmp++; } // Now the rest of the order is normally understood. for (nr = 0; nr < strlen(order); nr++){ // Sending is character by character. At the end // sending is done by WriteFile, therefore // strings have to be sent. char orderCharacter[2]; orderCharacter[0]=order[nr]; // orderCharacter is only a character. orderCharacter[1]='\0'; // now it is a string. sendReceiveCharacter(hSerial,orderCharacter); } ch[0]=sendReceiveCharacter(hSerial,"\x15"); // This character is the confirmation for PID that // order is complete. ch[0]=receiveCharacter(hSerial); // '.' is TC3215 ACK character. if(ch[0]!='.') fprintf(stderr,"Somethings wrong with Sending order.\n"); else fprintf(stdout,"Command sent, Sir!\n"); return 0; }
bool KeyboardDevice::writeText(const QString &text, int delay, bool noUnicodeCharacters) const { #ifdef Q_OS_UNIX bool result = true; KeySym keySym[2]; std::wstring wideString = text.toStdWString(); wchar_t wcSinglecharStr[2] = {L'\0'}; for(unsigned int i = 0; wideString[i] != L'\0' && i < wideString.size(); ++i) { wcSinglecharStr[0] = wideString[i]; //KeySym lookup keySym[0] = ActionTools::KeySymHelper::wcharToKeySym(wcSinglecharStr[0]); keySym[1] = 0; if(keySym[0] == 0 || ActionTools::KeySymHelper::keySymToKeyCode(keySym[0]) == 0) { //No keycode found -> try to find a Multi_key combination for this character keySym[0] = 0; for(int j = 0; j < ActionTools::KeySymHelper::MULTIKEY_MAP_SIZE; ++j) { if(wcSinglecharStr[0] == ActionTools::KeySymHelper::multikeyMapChar[j])//Found { keySym[0] = ActionTools::KeySymHelper::wcharToKeySym(ActionTools::KeySymHelper::multikeyMapFirst[j]); keySym[1] = ActionTools::KeySymHelper::wcharToKeySym(ActionTools::KeySymHelper::multikeyMapSecond[j]); if((ActionTools::KeySymHelper::keySymToKeyCode(keySym[0]) == 0) || (ActionTools::KeySymHelper::keySymToKeyCode(keySym[1]) == 0)) keySym[0] = 0;//Character not supported break; } } } if(keySym[0]) { if(keySym[1])//Multi key sequence { result &= sendKey("Multi_key"); result &= sendCharacter(keySym[0]); result &= sendCharacter(keySym[1]); } else//Single key result &= sendCharacter(keySym[0]); } if(delay > 0) ActionTools::CrossPlatform::sleep(delay); } return result; #endif #ifdef Q_OS_WIN std::array<INPUT, 2> input; SecureZeroMemory(input.data(), input.size() * sizeof(INPUT)); bool result = true; for(int i = 0; i < 2; ++i) { input[i].type = INPUT_KEYBOARD; input[i].ki.wVk = 0; if(noUnicodeCharacters) input[i].ki.dwFlags = KEYEVENTF_SCANCODE | (i == 0 ? 0 : KEYEVENTF_KEYUP); else input[i].ki.dwFlags = KEYEVENTF_UNICODE | (i == 0 ? 0 : KEYEVENTF_KEYUP); input[i].ki.time = 0; input[i].ki.dwExtraInfo = 0; } HKL keyboardLayout = GetKeyboardLayout(0); auto sendModifiersFunction = [&keyboardLayout](int key, int additionalFlags) { INPUT modifierInput; SecureZeroMemory(&modifierInput, sizeof(INPUT)); modifierInput.type = INPUT_KEYBOARD; modifierInput.ki.dwFlags = KEYEVENTF_SCANCODE | additionalFlags; modifierInput.ki.wScan = MapVirtualKeyEx(key, MAPVK_VK_TO_VSC, keyboardLayout); if(extendedKeys.count(key) > 0) modifierInput.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; SendInput(1, &modifierInput, sizeof(INPUT)); }; for(int i = 0; i < text.length(); ++i) { SHORT virtualKey = 0; if(noUnicodeCharacters) { virtualKey = VkKeyScanEx(text[i].unicode(), keyboardLayout); auto scanCode = MapVirtualKeyEx(LOBYTE(virtualKey), MAPVK_VK_TO_VSC, keyboardLayout); if(extendedKeys.count(virtualKey) > 0) { input[0].ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; input[1].ki.dwFlags |= KEYEVENTF_EXTENDEDKEY; } if(HIBYTE(virtualKey) & 1) //Shift sendModifiersFunction(VK_LSHIFT, 0); if(HIBYTE(virtualKey) & 2) //Control sendModifiersFunction(VK_LCONTROL, 0); if(HIBYTE(virtualKey) & 4) //Alt sendModifiersFunction(VK_LMENU, 0); input[0].ki.wVk = input[1].ki.wVk = virtualKey; input[0].ki.wScan = input[1].ki.wScan = scanCode; } else { input[0].ki.wScan = input[1].ki.wScan = text[i].unicode(); } result &= (SendInput(2, input.data(), sizeof(INPUT)) != 0); if(noUnicodeCharacters) { if(HIBYTE(virtualKey) & 4) //Alt sendModifiersFunction(VK_LMENU, KEYEVENTF_KEYUP); if(HIBYTE(virtualKey) & 2) //Control sendModifiersFunction(VK_LCONTROL, KEYEVENTF_KEYUP); if(HIBYTE(virtualKey) & 1) //Shift sendModifiersFunction(VK_LSHIFT, KEYEVENTF_KEYUP); } if(delay > 0) ActionTools::CrossPlatform::sleep(delay); } return result; #endif }
MyInputPanelContext::MyInputPanelContext() { inputPanel = new MyInputPanel; connect(inputPanel, SIGNAL(characterGenerated(QChar)), SLOT(sendCharacter(QChar))); }