| 225 | } |
| 226 | |
| 227 | bool CHookWindows::DisableWindowsKey() |
| 228 | { |
| 229 | // 方法1: 使用 RegisterHotKey 来占用 Windows 键 |
| 230 | bool success = true; |
| 231 | |
| 232 | // 注册热键来拦截 Windows 键 |
| 233 | if (!RegisterHotKey(nullptr, 1, MOD_WIN, VK_LWIN)) { |
| 234 | qCritical(log) << "注册左 Windows 键拦截失败:" << GetLastError(); |
| 235 | success = false; |
| 236 | } |
| 237 | |
| 238 | if (!RegisterHotKey(nullptr, 2, MOD_WIN, VK_RWIN)) { |
| 239 | qCritical(log) << "注册右 Windows 键拦截失败:" << GetLastError(); |
| 240 | success = false; |
| 241 | } |
| 242 | |
| 243 | // 方法2: 修改注册表禁用 Windows 键 |
| 244 | HKEY hKey; |
| 245 | LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, |
| 246 | L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", |
| 247 | 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, nullptr); |
| 248 | |
| 249 | if (result == ERROR_SUCCESS) { |
| 250 | DWORD value = 1; // 1 表示禁用 Windows 键 |
| 251 | result = RegSetValueExW(hKey, L"NoWinKeys", 0, REG_DWORD, |
| 252 | reinterpret_cast<const BYTE*>(&value), sizeof(value)); |
| 253 | |
| 254 | if (result == ERROR_SUCCESS) { |
| 255 | qDebug(log) << "注册表设置成功,Windows 键已禁用"; |
| 256 | } else { |
| 257 | qWarning(log) << "注册表设置失败:" << result; |
| 258 | success = false; |
| 259 | } |
| 260 | RegCloseKey(hKey); |
| 261 | } else { |
| 262 | qWarning(log) << "创建注册表键失败:" << result; |
| 263 | success = false; |
| 264 | } |
| 265 | |
| 266 | return success; |
| 267 | } |
| 268 | |
| 269 | bool CHookWindows::EnableWindowsKey() |
| 270 | { |
nothing calls this directly
no outgoing calls
no test coverage detected