| 188 | } |
| 189 | |
| 190 | bool SeizeInput::input_text(const std::string& text) |
| 191 | { |
| 192 | if (hwnd_) { |
| 193 | ensure_foreground(); |
| 194 | } |
| 195 | |
| 196 | auto u16_text = to_u16(text); |
| 197 | LogInfo << VAR(text) << VAR(u16_text) << VAR(hwnd_); |
| 198 | |
| 199 | // check_and_block_input(); |
| 200 | |
| 201 | // OnScopeLeave([this]() { unblock_input(); }); |
| 202 | |
| 203 | std::vector<INPUT> input_vec; |
| 204 | |
| 205 | for (const auto ch : u16_text) { |
| 206 | INPUT input = { }; |
| 207 | input.type = INPUT_KEYBOARD; |
| 208 | input.ki.dwFlags = KEYEVENTF_UNICODE; |
| 209 | input.ki.wScan = ch; |
| 210 | |
| 211 | input_vec.emplace_back(input); |
| 212 | |
| 213 | input.ki.dwFlags |= KEYEVENTF_KEYUP; |
| 214 | |
| 215 | input_vec.emplace_back(input); |
| 216 | } |
| 217 | |
| 218 | UINT written = SendInput(static_cast<UINT>(input_vec.size()), input_vec.data(), sizeof(INPUT)); |
| 219 | |
| 220 | if (written != input_vec.size()) { |
| 221 | LogError << VAR(written) << VAR(input_vec.size()) << VAR(u16_text.size()); |
| 222 | return false; |
| 223 | } |
| 224 | return true; |
| 225 | } |
| 226 | |
| 227 | bool SeizeInput::key_down(int key) |
| 228 | { |