4

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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Lanbo
  • 15,118
  • 16
  • 70
  • 147

1 Answers1

2

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.

dave4420
  • 46,404
  • 6
  • 118
  • 152
  • Would that only work if these Events are right after each other, without one in between? – Lanbo Jun 19 '12 at 14:44
  • Yes. You can use `filterE` to filter out events that shouldn't affect click-detection if you need to. – dave4420 Jun 19 '12 at 14:59
  • `previous` is the value that was passed in the immediately preceeding event, and `current` is the value that is passed in the current event. – dave4420 Jun 19 '12 at 15:01