[Fluxus] Key events

Carlos Alegria ccristoo at gmail.com
Fri Jun 8 07:04:32 PDT 2012


Hi Kassen,

I am making a 2D animation in which I am moving a plane with a texture. The
texture contains a music scroll, so the animation kind of resembles a
music-scroll player. I am trying to add movie-player-like controls using
keyboard input to play/pause the animation. I decided to assign the
play/pause control to the space bar.

My first approach was to use a PLAY flag that will be toggled at
(every-frame) using something like (when (key-pressed-this-frame " ") (set!
PLAY (not PLAY))). The problem was that (key-pressed-this-frame " ") returns
true in the frame where I press the space bar for the first time, but also
at some other frames after the first one, when the space bar is pressed
(before I released it again). This makes the play/pause control to work
intermittently, as a button press (i.e. button down, button press, and
button release events) is not usually done in the same frame.

I took a look into modules/scheme/input.ss to try to implement this behavior
as you said, but as I am new to fluxus I would first get familiar with its
source code. Thus, I ended up implementing all using (key-pressed-this-frame
" "):

(define KEY_DOWN (gensym))
(define KEY_PRESSED (gensym))
(define KEY_UP (gensym))

(define SPACE_KEY KEY_UP)
(define PLAY #t)

(define (render)
    ; keyboard handling
    ;
    (when (and (eq? SPACE_KEY KEY_UP) (key-pressed " "))
        (set! SPACE_KEY KEY_PRESSED))
    (when (and (eq? SPACE_KEY KEY_PRESSED) (not (key-pressed " ")))
        (set! SPACE_KEY KEY_UP)
        (set! PLAY (not PLAY)))

    ; rendering
    ;
    ....
)

(every-frame (render))

Originally, I was looking for a way in fluxus to accomplish this without the
need to implement everything by myself.

Thanks a lot,
Carlos Alegria

-----Original Message-----
From: 'Kassen' [mailto:signal.automatique at gmail.com] 
Sent: jueves, 07 de junio de 2012 19:05
To: gabor papp
Cc: Carlos Alegria; 'Fluxus'
Subject: Re: [Fluxus] Key events

On Thu, Jun 07, 2012 at 11:08:14PM +0200, gabor papp wrote:
> hi Carlos,
> 
> would you like something like a keypress event handler callback? as 
> far as i know there's no easy way to do this in fluxus at the moment.

Maybe I did misunderstand it all. Doesn't (key-pressed-this-frame ) when
invoked from (every-frame ) provide for the kind of usage case where we'd
use events in other languages? We'd be responding as fast as possible and
only once and in any way open to us, I'd think? There would be issues if the
frame-rate would drop below the haptic-rate, admittedly.

Yours,
Kas.




More information about the Fluxus mailing list