Next: , Previous: , Up: Interfacing with the mouse   [Contents][Index]


4.12.2 Getting the events

Once a class of mouse events have been enabled, getch and friends return KEY_MOUSE every time some mouse event happens. Then, the mouse event can be retrieved with getmouse.

getmouse returns a list of five elements: id, x, y, z, and flags. The flags contain information about mouse button events.

Schematically, decoding mouse events could look like this. (Note that I’ve used some of the srfi-1 list functions in this example.)

(set! c (getch win))
(if (eqv? c KEY_MOUSE)
    (let* ((m (getmouse))
           (mouse-x (second m))
           (mouse-y (third m))
           (mouse-flag (fifth m)))
       (cond
        ((logtest BUTTON1_PRESSED mouse-flag)
         ; do button1-pressed response here
        )
        ((logtest BUTTON1_RELEASED mouse-flag)
         ; do button1-released response here
        ))))