      PROGRAM mouse
      IMPLICIT NONE
      REAL x, y
      INTEGER IR_, s, ss, w, h, Itmp1_
      LOGICAL Ltmp1_
      DATA ss/3/
      CALL GWopen(IR_, 0)
      CALL GWsize(IR_, 1, w, h)
      Ltmp1_ = .TRUE.
      DO WHILE(Ltmp1_)
*        return current x and y window coordinates and state of mouse
         CALL GWmouse(IR_, Itmp1_, x, y)
         if(IR_ .NE. 0) THEN
           s = 1
         ELSE IF(Itmp1_ .NE. 0) THEN
           s = 2
         ELSE
           s = 3
         ENDIF
         IF(s .EQ. 1) THEN
            WRITE(*,*) ' left button down', x/w, y/h
         ELSE IF(s .EQ. 2) THEN
            WRITE(*,*) 'right button down', x/w, y/h
         ELSE IF(s .EQ. 3 .AND. ss .NE. s) THEN
            WRITE(*,*) '  button released', x/w, y/h
         END IF
         IF(IR_ .NE. 0 .AND. Itmp1_ .NE. 0) Ltmp1_ = .FALSE.
         ss = s
         CALL GWsleep(IR_, 1)
      END DO
      CALL GWquit(IR_)
      END
