Presses a hotkey combination (e.g., Win+R for Run dialog, Alt+F4 to close window, Ctrl+Alt+Delete for system menu). This endpoint allows for triggering keyboard shortcut combinations that are essential for operating a Windows system efficiently.
The endpoint simulates keyboard hotkey combinations, which can be used to:
Note: Consider using automation actions when possible instead of hotkeys as they can be more reliable in some situations. However, hotkeys are essential for certain system-level operations where no other interface is available.
This endpoint accepts a POST request with a JSON object containing the key to press.
Property | Type | Description |
---|---|---|
key Required |
String | The hotkey combination to press, in the format "Modifier1+Modifier2+...+Key" (e.g., "Win+R", "Alt+F4", "Ctrl+Alt+Delete") |
{
"key": "Win+R"
}
The response indicates whether the hotkey was successfully pressed.
Property | Type | Description |
---|---|---|
success |
Boolean | Indicates whether the hotkey was successfully pressed |
message |
String | Descriptive message about the operation result |
timestamp |
DateTime | The time when the operation was executed |
{
"success": true,
"message": "Pressed key: Win+R",
"timestamp": "2023-12-01T14:32:45.123Z"
}
import requests import json def press_hotkey(api_key, hotkey): url = "http://localhost:54321/tools-api/keyboard/press" headers = { "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } payload = { "key": hotkey } response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: return response.json() else: print(f"Error: {response.status_code}") print(response.text) return None # Example usage api_key = "your_api_key_here" # Open the Run dialog result = press_hotkey(api_key, "Win+R") print(f"Result: {result['message'] if result else 'Failed'}") # Close the current window result = press_hotkey(api_key, "Alt+F4") print(f"Result: {result['message'] if result else 'Failed'}") # Copy selected text result = press_hotkey(api_key, "Ctrl+C") print(f"Result: {result['message'] if result else 'Failed'}")
interface ActionResponse { success: boolean; message: string; timestamp: string; } async function pressHotkey(apiKey: string, hotkey: string): Promise
{ const url = "http://localhost:54321/tools-api/keyboard/press"; try { const response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${apiKey}` }, body: JSON.stringify({ key: hotkey }) }); if (!response.ok) { console.error(`Error: ${response.status}`); console.error(await response.text()); return null; } return await response.json() as ActionResponse; } catch (error) { console.error("Failed to press hotkey:", error); return null; } } // Example usage async function example() { const apiKey = "your_api_key_here"; // Open the Run dialog const runResult = await pressHotkey(apiKey, "Win+R"); console.log(`Run dialog result: ${runResult?.message || 'Failed'}`); // Wait a moment for the Run dialog to appear await new Promise(resolve => setTimeout(resolve, 500)); // Type "notepad" in the Run dialog // Note: This would require a separate call to the type endpoint // Press Enter to launch Notepad const enterResult = await pressHotkey(apiKey, "Enter"); console.log(`Enter key result: ${enterResult?.message || 'Failed'}`); }
using System; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; public class ToolsServerClient { private readonly HttpClient _httpClient; private readonly string _apiKey; public ToolsServerClient(string apiKey) { _httpClient = new HttpClient { BaseAddress = new Uri("http://localhost:54321") }; _apiKey = apiKey; _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); } public async Task
PressHotkeyAsync(string hotkey) { var request = new KeyboardActionRequest { key = hotkey }; var json = JsonSerializer.Serialize(request); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("/tools-api/keyboard/press", content); response.EnsureSuccessStatusCode(); var jsonResponse = await response.Content.ReadAsStringAsync(); return JsonSerializer.Deserialize (jsonResponse, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } } // Response and request models public class KeyboardActionRequest { public string key { get; set; } } public class ActionResponse { public bool success { get; set; } public string message { get; set; } public DateTime timestamp { get; set; } } // Example usage public class Example { public static async Task Main() { var client = new ToolsServerClient("your_api_key_here"); // Open the Run dialog var result = await client.PressHotkeyAsync("Win+R"); Console.WriteLine($"Result: {result.message}"); // Small delay to allow UI to respond await Task.Delay(500); // Launch Task Manager with Ctrl+Shift+Esc result = await client.PressHotkeyAsync("Ctrl+Shift+Esc"); Console.WriteLine($"Result: {result.message}"); } }