How to record mouse coordinates in fixed interval like 0.01ms?

1 view (last 30 days)
The mouse cursor is free moving, and I have to record the mouse coordinates X and Y in fixed interval like 0.01ms to a txt or excel file. Could someone help me with this? Thanks!

Answers (1)

Walter Roberson
Walter Roberson on 9 Dec 2015
Set up a timer that gets the PointerLocation property of the root graphics object.
  2 Comments
Yanlong Song
Yanlong Song on 10 Dec 2015
Hi Walter, thank you for the help! I still can not figure out how to do this. Could you give me some example code? Thanks!
Walter Roberson
Walter Roberson on 10 Dec 2015
Note that the below uses nested functions. You will need to put it into its own .m file unless your other code has "end" matching each "function" statement.
function recorded_points = trackcursor01(how_many)
recorded_points = [];
t = timer('TimerFcn', @getCursor, 'ExecutionMode', 'fixedRate', 'Period', 0.01, 'TasksToExecute', how_many, 'StartFcn', 'disp(''Go! Go! Go!'')' );
start(t);
wait(t);
stop(t); %should not be necessary but should not hurt
delete(t);
function getCursor(src, event) %nested function
this_location = get(0, 'PointerLocation');
recorded_points(end+1,:) = this_location;
end
end

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!