| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Subscription.Keyboard
Contents
Description
Overview
Miso.Subscription.Keyboard provides global keyboard subscriptions that
track which keys are currently held down. All four subscriptions register
keydown, keyup, and blur listeners on window; the blur handler
clears the pressed-key set so keys cannot get stuck when the window loses
focus.
Quick start
import Miso import Miso.Subscription.Keyboard -- Fire action with arrow-key state on every key change subs :: [SubAction] subs = [arrowsSubArrowsChanged ] update :: Action ->Effectp props Model Action update (ArrowsChanged (Arrowsx y)) = do -- x ∈ {-1, 0, 1}, y ∈ {-1, 0, 1}io_(move x y)
Subscription variants
keyboardSub— delivers the rawof all currently pressed keyCodes. Use this when you need to handle arbitrary key combinations.IntSet
arrowsSub— maps the four arrow keys (37–40) to anArrowsvalue witharrowX ∈ {-1, 0, 1}andarrowY ∈ {-1, 0, 1}.wasdSub— same asarrowsSubbut for W/A/S/D (keyCodes 87/83/65/68).directionSub— fully configurable: supply your own(up, down, left, right)keyCode lists and get the sameArrowsmapping.
See also
- Miso.Subscription — re-export hub
- Miso.Event.Types —
KeyCode,KeyInfo - Miso.Html.Event — per-element
onKeyDown/onKeyUp
Types
Type for arrow keys currently pressed.
- 37 left arrow ( x = -1 )
- 38 up arrow ( y = 1 )
- 39 right arrow ( x = 1 )
- 40 down arrow ( y = -1 )
Constructors
| Arrows | |
Instances
Subscriptions
Arguments
| :: ([Int], [Int], [Int], [Int]) |
|
| -> (Arrows -> action) | Callback fired with the current |
| -> Sub action |
Maps a specified list of keys to directions (up, down, left, right). The Ints represent keyCodes for each direction.