New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: continuous keydown events #551

Closed
jinjor opened this Issue Apr 5, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@jinjor
Contributor

jinjor commented Apr 5, 2016

Currently Keyboard module does not have API for continuous keydown events. Keyboard.isDown is fired only when value is changed, but I sometimes need many events when I keep keys pressing.

For example, I am implementing Undo/Redo triggered by ctrl+Z/ctrl+Y. I usually undo 100+ steps by keep ctrl+Z pressing, but this feature cannot be implemented using current API.

@halfzebra

This comment has been minimized.

Show comment
Hide comment
@halfzebra

halfzebra Apr 10, 2016

Contributor

You can achieve that by doing something like this, along with filtering for required key codes:

import Keyboard
import Signal
import Time
import Debug
import Graphics.Element exposing (show)


main =
  Keyboard.keysDown
  |> Signal.sampleOn (Time.fps 30)
  |> Signal.map show

Does that really require a core feature?

Contributor

halfzebra commented Apr 10, 2016

You can achieve that by doing something like this, along with filtering for required key codes:

import Keyboard
import Signal
import Time
import Debug
import Graphics.Element exposing (show)


main =
  Keyboard.keysDown
  |> Signal.sampleOn (Time.fps 30)
  |> Signal.map show

Does that really require a core feature?

@jinjor

This comment has been minimized.

Show comment
Hide comment
@jinjor

jinjor Apr 11, 2016

Contributor

Thanks, but I need different behavior. When some key is keeping pressed, The first event is fired immediately and the rest are fired after some interval. Like this:

a.......aaaaaaaaaaaaaaa

Also, I read the source and found the down state is made by filtering original events. I think it's more natural to use the original events than to reproduce new events.

Contributor

jinjor commented Apr 11, 2016

Thanks, but I need different behavior. When some key is keeping pressed, The first event is fired immediately and the rest are fired after some interval. Like this:

a.......aaaaaaaaaaaaaaa

Also, I read the source and found the down state is made by filtering original events. I think it's more natural to use the original events than to reproduce new events.

@Warry

This comment has been minimized.

Show comment
Hide comment
@Warry

Warry Apr 11, 2016

Repeating keys can be retrieved with keyup, but the core only supports keydown. I agree with @jinjor that it should be the developer's choice and should be available there.

Maybe we should expose document's events withOptions, just like for Html, where we can listen to an event by giving a string and a decoder.

Warry commented Apr 11, 2016

Repeating keys can be retrieved with keyup, but the core only supports keydown. I agree with @jinjor that it should be the developer's choice and should be available there.

Maybe we should expose document's events withOptions, just like for Html, where we can listen to an event by giving a string and a decoder.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 11, 2016

Member

I think this is solved in elm-lang/keyboard

Member

evancz commented May 11, 2016

I think this is solved in elm-lang/keyboard

@evancz evancz closed this May 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment