Skip to content

For keyboard use KeyboardEvent.code instead KeyboardEvent.key #16

@justgook

Description

@justgook

KeyboardEvent.key is good for somewhere where you need to type, and a is not same as A, but for something interactive - as games / visual interactive applications - better use KeyboardEvent.code - as for games - more important is position of button instead of it typing value.
Other critical part is when you would like (and most of gamers prefer) use WASD (ZQSD on AZERTY) fro player control, and that not matters what keyboard they use, other part if i would like use Shift key in combination with all that stuff, that would ruin all logic what im doing as it will require much more validations..

total off topic but you can save few renders with improving keyDown event:

            (D.field "key" D.string
                |> D.andThen
                    (\k ->
                        if Set.member k computer.keyboard.keys then
                            D.fail ""

                        else
                            D.succeed (KeyChanged True k)
                    )
            )```
that will not trigger non-renderable frame few times while player holds key (as it is sends keydown event few times in sec)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions