| 156 | } |
| 157 | |
| 158 | void Player::runSlice() { |
| 159 | // at least 10 ms between mouse moves |
| 160 | if (this->nextCommand == "MODIFIERS") { |
| 161 | currentInputModifiers = atoi(nextValue.c_str()); |
| 162 | instance->readCommand(); |
| 163 | } else if (this->nextCommand == "WHILEWAITING") { |
| 164 | std::vector<BString> items; |
| 165 | this->nextValue.split(',', items); |
| 166 | timerWhileWaiting = atoi(items[0].c_str()); |
| 167 | if (items.size() > 1) { |
| 168 | waitCommand = items[1]; |
| 169 | } |
| 170 | if (waitCommand == "LBUTTON") { |
| 171 | if (items.size() > 3) { |
| 172 | waitMouseX = atoi(items[2].c_str()); |
| 173 | waitMouseY = atoi(items[3].c_str()); |
| 174 | } else { |
| 175 | waitMouseX = 1; |
| 176 | waitMouseY = 1; |
| 177 | } |
| 178 | } else if (waitCommand == "KEY") { |
| 179 | waitKey = atoi(items[2].c_str()); |
| 180 | } |
| 181 | nextWaitTime = KSystem::getMilliesSinceStart() + timerWhileWaiting * 1000; |
| 182 | instance->readCommand(); |
| 183 | } |
| 184 | |
| 185 | if (KSystem::getMicroCounter()<this->lastCommandTime+10000) |
| 186 | return; |
| 187 | |
| 188 | KNativeScreenPtr screen = KNativeSystem::getScreen(); |
| 189 | KNativeInputPtr input = KNativeSystem::getCurrentInput(); |
| 190 | |
| 191 | if (this->nextCommand=="MOVETO") { |
| 192 | std::vector<BString> items; |
| 193 | this->nextValue.split(',', items); |
| 194 | if (items.size()!=2) { |
| 195 | klog_fmt("script: %s MOVETO should have 2 values: %s", this->directory.c_str(), this->nextValue.c_str()); |
| 196 | exit(99); |
| 197 | } |
| 198 | input->mouseMove(atoi(items[0].c_str()), atoi(items[1].c_str()), false); |
| 199 | instance->readCommand(); |
| 200 | return; |
| 201 | } |
| 202 | // 1000 ms between all other commands |
| 203 | if (KSystem::getMicroCounter()<this->lastCommandTime+1000000 && this->nextCommand!="MOUSEUP" && this->nextCommand!="KEYUP" && this->nextCommand != "SCREENSHOT" && !processWaitCommand) |
| 204 | return; |
| 205 | // at least 100 ms between mouse or key down/up |
| 206 | if (KSystem::getMicroCounter()<this->lastCommandTime+100000) |
| 207 | return; |
| 208 | |
| 209 | // process before any other command so that button up/down and key up/down stays balanced |
| 210 | if (processWaitCommand) { |
| 211 | if (waitCommand == "LBUTTON") { |
| 212 | processWaitCommand = false; |
| 213 | this->lastCommandTime = KSystem::getMicroCounter(); |
| 214 | input->mouseButton(0, 0, waitMouseX, waitMouseY); |
| 215 | klog("script WHILEWAITING LBUTTON"); |
no test coverage detected