Feature: Add remote_keyboard MCP tool (key_down / key_up / key_press / type)
Implement milestone M2b of the MCP remote-control design: inject keyboard events through an existing screen sub-connection. - Extract the MSG64 keyboard construction from WebService::HandleKey into a shared inline BuildKeyMsg64 helper in WebService.h, and have HandleKey use it (behaviour-preserving) so the Web and MCP paths cannot drift. - Add BuildRemoteKeyboard with four actions: key_down / key_up / key_press (key name -> VK via MapKeyNameToVk, plus CTRL/ALT/SHIFT/WIN modifiers) and type (per-character VkKeyScanA mapping, ASCII only, newline/tab -> Enter/Tab). The batch is sent as one [COMMAND_SCREEN_CONTROL][MSG64*N] packet over the screen sub-connection under the existing Begin/EndScreenCtrlAction busy discipline, then audited via WM_SHOWERRORMSG. Non-ASCII text is rejected (-32602) and must go through remote_clipboard + Ctrl+V (milestone M4), matching the design's clipboard path for CJK input. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
@@ -907,41 +907,8 @@ void CWebService::HandleKey(void* ws_ptr, const std::string& msg) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build MSG64 structure
|
||||
MSG64 msg64;
|
||||
memset(&msg64, 0, sizeof(MSG64));
|
||||
|
||||
// Use WM_SYSKEYDOWN/UP for Alt combinations (same as MFC version)
|
||||
if (altKey) {
|
||||
msg64.message = isDown ? WM_SYSKEYDOWN : WM_SYSKEYUP;
|
||||
} else {
|
||||
msg64.message = isDown ? WM_KEYDOWN : WM_KEYUP;
|
||||
}
|
||||
msg64.wParam = keyCode;
|
||||
msg64.time = GetTickCount();
|
||||
|
||||
// Build lParam for keyboard message:
|
||||
// bits 0-15: repeat count (1)
|
||||
// bits 16-23: scan code
|
||||
// bit 24: extended key flag
|
||||
// bit 29: context code (1 if Alt is pressed)
|
||||
// bit 30: previous key state (1 for keyup)
|
||||
// bit 31: transition state (1 for keyup)
|
||||
UINT scanCode = MapVirtualKey(keyCode, MAPVK_VK_TO_VSC);
|
||||
|
||||
// Extended keys: arrows, insert, delete, home, end, page up/down, numpad enter, etc.
|
||||
bool isExtended = (keyCode >= VK_PRIOR && keyCode <= VK_DOWN) || // Page Up/Down, End, Home, Arrows
|
||||
keyCode == VK_INSERT || keyCode == VK_DELETE ||
|
||||
keyCode == VK_NUMLOCK || keyCode == VK_RCONTROL || keyCode == VK_RMENU ||
|
||||
keyCode == VK_APPS;
|
||||
|
||||
LPARAM lParam = 1; // repeat count = 1
|
||||
lParam |= (scanCode & 0xFF) << 16;
|
||||
if (isExtended) lParam |= (1 << 24);
|
||||
if (altKey) lParam |= (1 << 29); // context code for Alt
|
||||
if (!isDown) lParam |= (3UL << 30); // bit 30 and 31 set for key up
|
||||
|
||||
msg64.lParam = lParam;
|
||||
// Build MSG64 structure(共享 helper,见 WebService.h;与 MCP remote_keyboard 复用)
|
||||
MSG64 msg64 = BuildKeyMsg64(keyCode, isDown, altKey);
|
||||
|
||||
// Send command to device
|
||||
const int length = sizeof(MSG64) + 1;
|
||||
|
||||
Reference in New Issue
Block a user