key_press
Send keyboard shortcuts to Hyprland windows, optionally targeting specific applications without changing window focus. Use key combinations like "ctrl+c" or "alt+F4" for desktop automation.
Instructions
Press a key combination.
Uses Hyprland's native sendshortcut — can target specific windows without focusing them.
Args: keys: Key combo string like "ctrl+c", "alt+F4", "super+1", "Return" target: Optional window selector to send the key to (e.g. "class:firefox"). If omitted, sends to the active window.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keys | Yes | ||
| target | No |
Implementation Reference
- hyprland_mcp/input.py:134-151 (handler)The core implementation of the key_press functionality that dispatches the command to hyprctl.
async def key_press(keys: str, target: str | None = None) -> None: """Press a key combination using hyprctl dispatch sendshortcut. Args: keys: Key combo like "ctrl+c", "alt+F4", "Return", "super+1" target: Optional window selector """ # Parse "ctrl+shift+c" into mods="CTRL SHIFT" and key="c" parts = keys.split("+") if len(parts) == 1: mods = "" key = parts[0] else: key = parts[-1] mods = " ".join(p.upper() for p in parts[:-1]) target_str = target or "" await hyprctl.dispatch("sendshortcut", f"{mods}, {key}, {target_str}") - hyprland_mcp/server.py:330-344 (registration)The MCP tool registration for key_press.
@mcp.tool() async def type_text(text: str, delay_ms: int = 0) -> str: """Type text as if from a keyboard. Args: text: The text to type delay_ms: Delay between keystrokes in milliseconds (0 = instant) """ from . import input as inp await inp.type_text(text, delay_ms=delay_ms) return f"Typed {len(text)} characters" @mcp.tool() async def key_press(keys: str, target: str | None = None) -> str: