[plt-scheme] mouse event

From: Eduardo Cavazos (proteus at theworld.com)
Date: Tue May 6 14:45:30 EDT 2003

> Can you give me some examples of mouse event in a canvas (return pos x
> and y when you click the canvas).
> Thank you.


Below is an example you can paste into a DrScheme window. There's an
example from which this is derived in the MrEd manual:


(define *frame* (instantiate frame% ()
                  (label "Foo")
                  (width 100)
                  (height 100)))

(define my-canvas%
  (class canvas% ; The base class is canvas%
    ;; Declare overrides:
    (override on-event)
    ;; Define overriding method to handle mouse events
    (define on-event (lambda (event)
                       (if (send event button-down? 'any)
                           (display (list (send event get-x)
                                          (send event get-y))))))
    ;; Call the superclass initialization (and pass on all init args)
    (super-instantiate ())))

;; Make a canvas that handles events in the frame
(instantiate my-canvas% (*frame*))

(send *frame* show #t)

Posted on the users mailing list.