# <scanner>

A live camera viewfinder that reads QR codes and runs on-scan with the code it found.

Category: Media. Also written `<qr-scanner>`. Uses camera.

This tag needs a camera, so try it on your phone.

```ham
<column style="gap-12">
    <scanner id="scan"
             style="h-320 rounded-lg"
             on-scan="$code = $event.value"/>
    <text style="muted">Point the camera at a ticket's QR code.</text>
</column>
```

How Hype Apps draws it on a phone: [light](https://hypeapps.dev/img/tags/scanner-light.webp), [dark](https://hypeapps.dev/img/tags/scanner-dark.webp).

## Attributes

| Name | What it does | Default |
|---|---|---|
| `cooldown` | Seconds before the same code can fire again. Unset: each code fires once while the scanner is on screen. |  |
| `facing` | Which camera. (back, front) | `back` |
| `frame` | Draw the corner brackets showing where to hold the code. | `true` |
| `torch` | Start with the torch on. | `false` |

## Commands

| Name | What it does |
|---|---|
| `pause` | Stop reading codes (the preview stays); \$id.scanning goes false. |
| `reset` | Forget the codes already read, so each can fire again. |
| `resume` | Read codes again. |
| `torch` | Toggle the torch, or set it; \$id.torch follows. |

## Events

| Name | What it does |
|---|---|
| `on-scan` | Statements to run when a code is read (same as @on.scan / action-scan): on-scan="auth:pair:\$event.query.code". |

## Readings

| Name | What it does |
|---|---|
| `scanning` | Whether codes are being read. |
| `torch` | Whether the torch is on. |
| `value` | The last code read. |

Any tag also takes gestures: `@on.tap`, `@on.longpress`, `@on.doubletap` and `@on.swipeleft` (and right, up and down). `@click` runs on a tap too.

## Related tags

- [`<column>`](https://hypeapps.dev/docs/reference/column.md): Stacks its children top to bottom, with a gap between them and an alignment across.
- [`<text>`](https://hypeapps.dev/docs/reference/text.md): A run of text; with @text it shows an expression that updates as its variables change.
- [`<audio>`](https://hypeapps.dev/docs/reference/audio.md): A compact audio player bar with play, a progress track and the track's title and artist.
- [`<camera>`](https://hypeapps.dev/docs/reference/camera.md): A live camera viewfinder with a shutter; the photo's path goes into a variable.
- [`<canvas>`](https://hypeapps.dev/docs/reference/canvas.md): A drawing surface for finger or stylus, with a pen, eraser and color toolbar; it saves as a PNG.
- [`<file-picker>`](https://hypeapps.dev/docs/reference/file-picker.md): Opens the device's photo, video or file picker (or the camera) and puts the chosen file in a variable.
- [`<img>`](https://hypeapps.dev/docs/reference/img.md): Shows a picture from a URL or the app's files, sized and cropped by its style.
- [`<layer>`](https://hypeapps.dev/docs/reference/layer.md): Declares one layer of a drawing surface: a locked picture to trace over, and a layer to paint on.

All tags: https://hypeapps.dev/docs/reference.md · The full reference: https://hypeapps.dev/llms.txt
