function Mouse
% Sample script Mouse v1.24
% Uses low-level graphics primitives rather than Cogent 2000 commands
%
% Move the cursor into the display.
% Hit a mouse button to exit
fprintf('\nMove the cursor into the display.\n\n');
fprintf('Hit a mouse button to exit\n\n')

cgloadlib;        %load Cogent low-level graphics lobrary
cgopen(1,0,0,0);  %open 640x480 video Window
cgpencol(1,1,1);  %set drawing color to WHITE

%loop until button press event
%returned from cgmouse() routine
bp=0;
while ~bp
   %fetch current status of mouse
   %(x,y) = position; bp = button events (1=left, 4=right button press)
   [x,y,bd,bp]=cgmouse;
   %draw 100x100 ellipse at current x,y mouse position
   %into backbuffer (i.e., screen buffer #0)
   cgellipse(x,y,100,100,'f')  
   %copy contents of backbuffer to video screen
   %then clear backbuffer to BLACK (0,0,0)
   cgflip(0,0,0)
end

%report exit state
display('Mouse activity at exit:');
display(['x = ',num2str(x)]);
display(['y = ',num2str(y)]);
display(['button pressed = ',num2str(bp)]);
display('   Left = 1; Right = 4');

%close video window and exit script
cgshut  
return
