How can I record mouse clicks (left and right) with coordinates and time?

조회 수: 5 (최근 30일)
Doli Swey
Doli Swey 2021년 3월 5일
댓글: Doli Swey 2021년 3월 8일
Hello,
I am trying to capture mouse movements outside of the GUI, on second display while users are using another program. So far, I manage to record the coordinates, every 0.1 seconds period, by using timer function. I need to add mouse clicks (left or right button down and ups). Does anyone know how can I do this? I try to Buttondownfnc but it only works with a figures not outside of the Matlab..or is there any workaround?
fileID = fopen('motion.txt','wt');
t = timer('ExecutionMode', 'fixedRate','Period', 0.1, 'TasksToExecute', 200, ...
'TimerFcn', @(~,~) fprintf(fileID,'(X, Y) = (%g, %g)\n', get(0, 'PointerLocation')));
start(t);
  댓글 수: 8
Mario Malic
Mario Malic 2021년 3월 6일
Some of the Adobe programs support the Active X controls IIRC, maybe your software supports that, if it does, maybe there are methods that track mouse movement.
Doli Swey
Doli Swey 2021년 3월 6일
Hi Mario, thank you for your suggestion. What is Active X controls IIRC? I dont know anything about it and i couldnt find so much information online. Can you maybe give me a link to understand?

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2021년 3월 6일
편집: Jan 2021년 3월 6일
You can emulate this with WindowsAPI. Setting the window completely invisble does not work, because with Alpha=0.0 the mouse events are not caught anymore. But with Alpha= 0.01 you cannot see the window anymore, but clicks are still caught:
FigH = figure;
FigH.ButtonDownFcn = @(FigH, Event) disp(Event);
drawnow;
% Set inner window covers complete screen on monitor m'th monitor:
m = 1;
WindowAPI(FigH, 'Position', 'full', m);
% Allmost transparent (I do not see anything, do you):
WindowAPI(FigH, 'Alpha', 0.01);
% Crop window border, such this does not cover the margins
% of other monitors:
WindowAPI(FigH, 'Clip', true);
% Set window to top or catch at least the focus:
WindowAPI(FigH, 'Top');
WindowAPI(FigH, 'SetFocus');
for k = 1:100
pause(0.1)
disp(get(groot, 'PointerLocation'))
end
delete(FigH); % Important: Otherwise the window steals all events!
  댓글 수: 5
Jan
Jan 2021년 3월 8일
My suggestion would be to record the mouse clicks in the transparent window, move the Acrobat window to top an to emulate the formerly recorded mouse clicks.
For fast double clicks this might fail. With SendMessage there is no need for a time consuming movement of the Acrobat window to the top. But as said already, I did not get the Mex-function to work.
There are some mouse recording softwares, which track the mouse position and the clicks. Do you have a good reason to do this in Matlab?
Doli Swey
Doli Swey 2021년 3월 8일
Yes because I am using tablet with pen, the third party mouse recorders somehow do not track the touch (left clck) and pen button (right click).
My suggestion would be to record the mouse clicks in the transparent window, move the Acrobat window to top an to emulate the formerly recorded mouse clicks.
I have tried but it is not possible to move the Adobe software on top of the transparent window once I start run the script. I will try to find a workaround with the code you sent. Thank you so much. I will keep you updated.
Appriciate the help!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by