MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / input_text

Method input_text

source/MaaWin32ControlUnit/Input/LegacyEventInput.cpp:131–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131bool LegacyEventInput::input_text(const std::string& text)
132{
133 if (hwnd_) {
134 ensure_foreground();
135 }
136
137 auto u16_text = to_u16(text);
138 LogInfo << VAR(text) << VAR(u16_text) << VAR(hwnd_);
139
140 // check_and_block_input();
141 // OnScopeLeave([this]() { unblock_input(); });
142
143 // 使用旧的keybd_event API(已废弃,但某些情况下可能仍然有效)
144 for (const auto ch : u16_text) {
145 // keybd_event不支持Unicode,只能发送虚拟键码
146 // 这里简化处理,只发送字符码
147 keybd_event(static_cast<BYTE>(ch), 0, 0, 0);
148 keybd_event(static_cast<BYTE>(ch), 0, KEYEVENTF_KEYUP, 0);
149 std::this_thread::sleep_for(std::chrono::milliseconds(50));
150 }
151
152 return true;
153}
154
155bool LegacyEventInput::key_down(int key)
156{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected