elm-playground
elm-playground copied to clipboard
For keyboard use `KeyboardEvent.code` instead `KeyboardEvent.key`
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)