# Desktop Input (HID)

> Simulate Keyboard/Mouse input.

Source: https://docs.sommatic.ai/en/nodes/io.desktop.input/

- Slug: `io.desktop.input`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Simulate Keyboard/Mouse input.

## Configuration

- `type` (string, required): Default: `keyboard`. Allowed values: `keyboard`, `mouse`.
- `action` (string, required): Allowed values: `type`, `click`, `move`, `keyTap`.
- `payload` (object, optional): { text, x, y, key, modifier }

## Output ports

- `out` (default): Input action simulated
- `error`: Simulation failed

## Input contract

- `type` (string, required)
- `action` (string, required)
- `payload` (object, optional)

## Output contract

- `success` (boolean, optional)

## In expressions

What a later node can read from this node's output with `$("Desktop Input (HID)").item.json.<path>` (write your node's label instead of `Desktop Input (HID)`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Desktop Input (HID)").item.json.success` (boolean) = `true`


## How it works

Simulates one keyboard or mouse action (type text, tap a key, move the pointer or left-click) on the machine that runs the worker.

1. Checks that the native input module is loaded; if not, leaves through `error` without doing anything.
2. Resolves the config. `type` (default `keyboard`) and `action` fall back to the same keys of the incoming payload.
3. Reads the action arguments `text`, `x`, `y`, `key` and `modifier` from `payload.payload`, else from `payload`. When the node config has no `payload`, `payload` is the incoming data.
4. Keyboard: `type` types `text`; `keyTap` taps `key` with an optional `modifier` (string or array). Mouse: `move` moves to (`x`, `y`), defaulting to 0; `click` left-clicks at the current position.
5. Returns `{ success: true }` through `out`.

## In a workflow

### Node

```json
{
  "node_id": "node-type-reference",
  "label": "Type reference",
  "operator_slug": "io.desktop.input",
  "operator_version": "1.0.0",
  "config": {
    "type": "keyboard",
    "action": "type",
    "payload": {
      "text": "{{ $json.reference }}"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "success": true
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The action ran. Also fires when the `type`/`action` combination matches nothing, in which case nothing was simulated.

```json
{
  "success": true
}
```

### `error`

The native input module is not available, or the action failed (for example, an invalid key name).

```json
{
  "error": "RobotJS Native Module not available in this environment"
}
```

## Behaviour in the code

- `action`: Valid pairs: `keyboard` + `type`/`keyTap`, `mouse` + `move`/`click`. Any other pair is a silent no-op that still leaves through `out`.
- `payload`: Holds the action arguments `{ text, x, y, key, modifier }`. A nested `payload.payload` takes precedence. `click` ignores `x` and `y`; move first.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `RobotJS Native Module not available in this environment` | `error` | The native input library could not be loaded on the host (no desktop session or unsupported platform). Run the node on a machine with a desktop session. |
| `<input library error message>` | `error` | The library rejected the arguments, typically a missing or unknown `key` for `keyTap`. Pass a valid key name. |

## Notes and limits

- Input is injected into the active desktop session of the host that runs the worker; whatever window has focus receives it.
- One node performs exactly one action. Chain several nodes for a sequence (for example `move`, then `click`, then `type`).


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "io.desktop.input",
  "name": "Desktop Input (HID)",
  "category": "io",
  "version": "1.0.0",
  "description": "Simulate Keyboard/Mouse input.",
  "capabilities": [
    "hid",
    "keyboard",
    "mouse",
    "desktop"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "type": {
        "type": "string",
        "enum": [
          "keyboard",
          "mouse"
        ],
        "default": "keyboard"
      },
      "action": {
        "type": "string",
        "enum": [
          "type",
          "click",
          "move",
          "keyTap"
        ]
      },
      "payload": {
        "type": "object",
        "description": "{ text, x, y, key, modifier }"
      }
    },
    "required": [
      "type",
      "action"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "type": {
        "type": "string"
      },
      "action": {
        "type": "string"
      },
      "payload": {
        "type": "object"
      }
    },
    "required": [
      "type",
      "action"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "success": {
        "type": "boolean"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Done",
      "description": "Input action simulated",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Simulation failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent"
  ],
  "tags": [
    "desktop",
    "hid"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string",
      "enum": [
        "keyboard",
        "mouse"
      ],
      "default": "keyboard"
    },
    "action": {
      "type": "string",
      "enum": [
        "type",
        "click",
        "move",
        "keyTap"
      ]
    },
    "payload": {
      "type": "object",
      "description": "{ text, x, y, key, modifier }"
    }
  },
  "required": [
    "type",
    "action"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": "string"
    },
    "action": {
      "type": "string"
    },
    "payload": {
      "type": "object"
    }
  },
  "required": [
    "type",
    "action"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "success": {
      "type": "boolean"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Done",
    "description": "Input action simulated",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Simulation failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
