recording the mouse position

  • Follow


Here is a modification of some code a kind soul posted on the web. I
would like to collect data while the mouse is down.

What happens is that the program takes the data in only if the mouse
is right on the dot.
I think that is because the even handler that starts the program is
somehow attached to the dot, and not to the whole plot. What do I need
to do to be able to record mouse position as soon as the stylus is
down, regardless of the initial dot position on the screen?

function main
clear all
close all
global data

data=[];
f = figure;
aH = axes('Xlim', [0, 1], 'YLim', [0 1]);

h = plot(0.25, 0.25, '.', 'MarkerSize', 10, 'ButtonDownFcn',
@startDragFcn);
%     'Marke2rEdgeColor'    , 'k',    ...
%     'MarkerFaceColor'    , 'r',    ...
%     'MarkerSize', 10, ...
%     'linewidth', 3,        ...
%   'ButtonDownFcn', @startDragFcn);
axis([0,1,0,1])
hold on

set(f,'WindowButtonUpFcn', @stopDragFcn);

  function startDragFcn(varargin)

    set(f, 'WindowButtonMotionFcn', @draggingFcn)

  end

  function draggingFcn(varargin)

    pt = get(aH, 'CurrentPoint');
    plot(pt(1,1),pt(1,2),'.');
    data=[data;[pt(1,1:2)]];

  end

  function stopDragFcn(varargin)

    set(f, 'WindowButtonMotionFcn', '');
    data
  end

end

0
Reply anne (264) 2/19/2009 8:21:18 PM

Is there some other way that people use to record mouse position.

The requirement is that the record start when the person put the pen
down, and stop when the person bring the pen up.
0
Reply anne (264) 2/20/2009 4:13:29 PM


anne001 <anne@wjh.harvard.edu> wrote in message <b5799c89-d068-4e27-9fd3-5f35f0443037@v13g2000yqm.googlegroups.com>...
> Is there some other way that people use to record mouse position.
> 
> The requirement is that the record start when the person put the pen
> down, and stop when the person bring the pen up.

% Try this:
% In your above code, replace (actually insert a new line):

axis([0,1,0,1])
hold on

% with:

axis([0,1,0,1])
set(aH, 'ButtonDownFcn',@startDragFcn)
hold on
0
Reply someone3 (1540) 2/20/2009 7:02:03 PM

Thank you so much
0
Reply anne (264) 2/25/2009 5:05:04 PM

3 Replies
50 Views

(page loaded in 0.121 seconds)

Similiar Articles:













7/15/2012 8:03:39 PM


Reply: