| 156 | namespace op::hook::input_hook_client { |
| 157 | |
| 158 | long Bind(HWND hwnd, int mode) { |
| 159 | if (!::IsWindow(hwnd)) |
| 160 | return 0; |
| 161 | |
| 162 | std::lock_guard<std::mutex> lock(g_mutex); |
| 163 | auto &refs = g_bind_refs[hwnd]; |
| 164 | // 鼠标和键盘 dx 会共用同一个目标进程 Hook,宿主侧只做一次注入。 |
| 165 | if (refs > 0) { |
| 166 | ++refs; |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | const long ret = call_set_input_hook(hwnd, mode); |
| 171 | if (ret == 1) { |
| 172 | refs = 1; |
| 173 | } else { |
| 174 | g_bind_refs.erase(hwnd); |
| 175 | } |
| 176 | return ret; |
| 177 | } |
| 178 | |
| 179 | long UnBind(HWND hwnd) { |
| 180 | if (!hwnd) |
no test coverage detected