> For the complete documentation index, see [llms.txt](https://viridian-games.gitbook.io/pixel-palette/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://viridian-games.gitbook.io/pixel-palette/core-components/input-system/input-sources-and-priority.md).

# Input Sources & Priority

`TryGetDrawingInput()` checks three devices in strict priority order and returns the first active one:

```
1. Pen (tablet stylus)
   └─ Pen.current.tip.isPressed
   └─ Pen.current.position.ReadValue()      → screen position
   └─ Pen.current.pressure.ReadValue()      → 0..1 pressure (clamped min 0.05)

2. Touch (finger)
   └─ Touchscreen.current.primaryTouch.press.isPressed
   └─ AND !hasSeenMultiTouch  (suppressed during pinch)
   └─ Touchscreen.current.primaryTouch.position.ReadValue()
   └─ pressure = 1.0 (always, touch doesn't report pressure)

3. Mouse (fallback)
   └─ Mouse.current.leftButton.isPressed
   └─ Mouse.current.position.ReadValue()
   └─ pressure = 1.0
```

This means if you have a pen connected, mouse clicks are ignored while the pen is down. Touch takes priority over mouse but not pen.

### Device-Specific Behavior

| Feature        | Pen                     | Touch              | Mouse                   |
| -------------- | ----------------------- | ------------------ | ----------------------- |
| **Drawing**    | Yes, with pressure      | Yes, single finger | Left-click drag         |
| **Pan**        | N/A                     | Two-finger drag    | Right/middle-click drag |
| **Zoom**       | N/A                     | Two-finger pinch   | Scroll wheel            |
| **Pressure**   | Pen pressure (0.05–1.0) | N/A (1.0)          | N/A (1.0)               |
| **Double-tap** | Yes                     | Yes                | Yes                     |

### Touch Pan & Zoom (HandleTouchPanZoom)

Two-finger gesture detection:

```
Count touches with press.isPressed
  if 0 → reset multi-touch flag
  if 1 → single touch (drawing allowed)
  if 2+ → set hasSeenMultiTouch, enter pan/zoom mode
```

Once in two-finger mode:

* **Pan** — average delta of both fingers → `viewController.Pan(delta)`
* **Pinch zoom** — distance change between fingers → `viewController.Zoom(factor, center, camera)`

The `hasSeenMultiTouch` flag prevents single-finger drawing during/after a pinch gesture until all fingers lift.

### Mouse Pan (HandleMousePan)

```
bool panPressed = rightButton || middleButton;
```

Right-click or middle-click hold → tracks `Mouse.current.delta` → `viewController.Pan(delta)`. Sets `isPanning = true` plus a 2-frame `panCooldown` so releasing the button doesn't immediately start drawing at that position.

### Mouse Scroll Zoom (HandleMouseScrollZoom)

```
float scroll = Mouse.current.scroll.ReadValue().y;
```

Scroll up → zoom in (×1.1), scroll down → zoom out (÷1.1). Zoom centers on the mouse cursor position via `viewController.Zoom(factor, screenPos, camera)`.

### Internal State Tracking

* `isDrawing` — true while any stroke is active (pen/touch/mouse down)
* `isPanning` — true while panning via right-click or two-finger touch
* `isSelectionMoving` — true while dragging a selection's content
* `hasSeenMultiTouch` — true after any two-finger touch event, reset on all fingers up
* `quickShapeActive` — true after the hold-still timer triggers quick-shape mode
* `panCooldown` — frame counter preventing accidental drawing after pan release
* `lastTapTime` / `lastTapPosition` — for double-tap detection (0.3s window, 20px distance)

### Camera Resolution

`ResolveEventCamera()` determines which camera to use for screen-to-pixel conversion:

```
canvas.GetCanvas()
  if null → Camera.main
  if ScreenSpaceOverlay → null (screen coords are pixel coords)
  if ScreenSpaceCamera → canvas.worldCamera or Camera.main
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viridian-games.gitbook.io/pixel-palette/core-components/input-system/input-sources-and-priority.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
