All Projects → ohanhi → Keyboard Extra

ohanhi / Keyboard Extra

Licence: bsd-3-clause
Nice handling for keyboard inputs in Elm

Programming Languages

elm
856 projects

Labels

Projects that are alternatives of or similar to Keyboard Extra

Mechanical Keyboard
DIY mechanical keyboard and where to find them
Stars: ✭ 947 (+1756.86%)
Mutual labels:  keyboard
Typist
Swift UIKit keyboard manager for iOS apps.
Stars: ✭ 1,011 (+1882.35%)
Mutual labels:  keyboard
Commonkeyboard
An elegant Keyboard library for iOS. simple, lightweight and standalone no sub-dependencies required
Stars: ✭ 47 (-7.84%)
Mutual labels:  keyboard
Emojikeyboard
自定义表情键盘(支持系统表情, 图片表情),仅供参考学习~
Stars: ✭ 33 (-35.29%)
Mutual labels:  keyboard
React Spreadsheet Grid
An Excel-like grid component for React with custom cell editors, performant scroll & resizable columns
Stars: ✭ 996 (+1852.94%)
Mutual labels:  keyboard
Tertiary text
[Pebble] Tertiary text input for the Pebble!
Stars: ✭ 43 (-15.69%)
Mutual labels:  keyboard
Voyager65 Keyplus
65% keyboard PCB for Keyplus firmware. Simplified variants available.
Stars: ✭ 29 (-43.14%)
Mutual labels:  keyboard
Keyboardlayoutguide
⌨️ Manage iOS keyboard with Apple's missing KeyboardLayoutGuide
Stars: ✭ 1,054 (+1966.67%)
Mutual labels:  keyboard
Kfreestyle2d
Unofficial Kinesis Freestyle 2 Userspace Linux Driver
Stars: ✭ 41 (-19.61%)
Mutual labels:  keyboard
Gingham pcb
A 60% throughole keyboard inspired by the Plaid
Stars: ✭ 45 (-11.76%)
Mutual labels:  keyboard
Cmd Toutiao
摸鱼神器:在命令行中看今日头条
Stars: ✭ 34 (-33.33%)
Mutual labels:  keyboard
Jquery Keyfilter
This plugin filters keyboard input by specified regular expression.
Stars: ✭ 37 (-27.45%)
Mutual labels:  keyboard
Pxt Bluetooth Keyboard
BLE HID Keyboard module for micro:bit
Stars: ✭ 44 (-13.73%)
Mutual labels:  keyboard
Typing Assistant
Typing Assistant provides the ability to autocomplete words and suggests predictions for the next word. This makes typing faster, more intelligent and reduces effort.
Stars: ✭ 32 (-37.25%)
Mutual labels:  keyboard
Atreis
Stars: ✭ 48 (-5.88%)
Mutual labels:  keyboard
Silence
A simple, clean macro recorder written in C#. Windows 10 compatible.
Stars: ✭ 29 (-43.14%)
Mutual labels:  keyboard
Inputsystem
An efficient and versatile input system for Unity.
Stars: ✭ 1,013 (+1886.27%)
Mutual labels:  keyboard
Capsicain
Powerful low-level keyboard remapping tool for Windows
Stars: ✭ 51 (+0%)
Mutual labels:  keyboard
Keyboardheightprovider
Get android keyboard height using an overlay popup-window
Stars: ✭ 50 (-1.96%)
Mutual labels:  keyboard
Skr
Low level key re-programming
Stars: ✭ 47 (-7.84%)
Mutual labels:  keyboard

Keyboard Extra

Nice keyboard inputs in Elm.

It is quite tedious to find out the currently pressed down keys with just the Keyboard module, so this package aims to make it easier.

You can use Keyboard.Extra in two ways:

  1. The "Msg and Update" way, which has some setting up to do but has a bunch of ways to help you get the information you need.
  2. The "Plain Subscriptions" way, where you get subscriptions for keys' down and up events, and handle the rest on your own.

Full examples you can run and play with on Ellie

All of the examples are also in the example directory in the repository.

Msg and Update

If you use the "Msg and Update" way, you will get the most help, such as:

  • All keyboard keys are named values of the Key type, such as ArrowUp, CharA and Enter
  • You can find out whether e.g. Shift is pressed down when any kind of a Msg happens in your program
  • Arrow keys and WASD can be used as { x : Int, y : Int } or as a union type (e.g. South, NorthEast)
  • You can also get a full list of keys that are pressed down

When using Keyboard.Extra like this, it follows The Elm Architecture. Its model is a list of keys, and it has an update function and some subscriptions. Below are the necessary parts to wire things up. Once that is done, you can get useful information using the helper functions such as arrows and arrowsDirection.


Include the list of keys in your program's model

import Keyboard.Extra exposing (Key)

type alias Model =
    { pressedKeys : List Key
    -- ...
    }

init : ( Model, Cmd Msg )
init =
    ( { pressedKeys = []
      -- ...
      }
    , Cmd.none
    )

Add the message type in your messages

type Msg
    = KeyMsg Keyboard.Extra.Msg
    -- ...

Include the subscriptions for the events to come through (remember to add them in your main too)

subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.batch
        [ Sub.map KeyMsg Keyboard.Extra.subscriptions
        -- ...
        ]

And finally, you can use update to have the list of keys be up to date

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        KeyMsg keyMsg ->
            ( { model | pressedKeys = Keyboard.Extra.update keyMsg model.pressedKeys }
            , Cmd.none
            )
        -- ...

Now you can get all the information anywhere where you have access to the model, for example like so:

calculateSpeed : Model -> Float
calculateSpeed model =
    let
        arrows =
            Keyboard.Extra.arrows model.pressedKeys
    in
        model.currentSpeed + arrows.x


isShooting : Model -> Bool
isShooting model =
    List.member Space model.pressedKeys

Have fun! :)


PS. The Tracking Key Changes example example shows how to use updateWithKeyChange to find out exactly which key was pressed down / released on that update cycle.

Plain Subscriptions

With the "plain subscriptions" way, you get the bare minimum:

  • All keyboard keys are named values of the Key type, such as ArrowUp, CharA and Enter

Setting up is very straight-forward:

type Msg
    = KeyDown Key
    | KeyUp Key
    -- ...


subscriptions : Model -> Sub Msg
subscriptions model =
    Sub.batch
        [ Keyboard.Extra.downs KeyDown
        , Keyboard.Extra.ups KeyUp
        -- ...
        ]

There's an example for this, too: Plain Subscriptions

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].