How to record mouse coordinates in fixed interval like 0.01ms?
1 view (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Walter Roberson
on 9 Dec 2015
Set up a timer that gets the PointerLocation property of the root graphics object.
2 Comments
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
See Also
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!