Question

A full click event is a button down and up, without mouse motion, as far as I know. SDL only gives me Button Up and Down events.

Does reactive-banana have any way to express "key down and then key up"?

Incidentally, if I want to have an event that says "key still down", I have to enable SDL's enableKeyRepeat so the keyDown event is fired again. How would that be expressed correctly in FRP?

Was it helpful?

Solution

I'd try something like this:

Define a utility function (untested):

successive :: (a -> a -> Maybe b) -> Event t a -> Event t b
successive f e = filterJust (b <@> e)
  where b = stepper (const Nothing) (f <$> e)

and then use something like

successive (\previous current -> if previous == buttonDown && current == buttonUp
                                   then Just ()
                                   else Nothing)
           buttonEvents

(pseudo-code because I'm not familiar with SDL).

This should work because behaviours update fractionally after events fire.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top