I am creating a demo using MATLAB and I would like to programmatically move and click the mouse to demonstrate my application.
MATLAB: How to programmatically control mouse motion and clicks with MATLAB
automatic;MATLABmicemove
Related Solutions
As this answer, there is no direct way to acquire what you want. But there is an indirect way, by simulating keyboard press, mouse movement and mouse clicking. Here's an example (platform: Windows) for copying elements in the Chrome DevTools into Matlab Workplace and perhaps you can modify it accordingly.
system('start chrome "https://www.google.com/"');import java.awt.*;import java.awt.event.*;% press F12 to activate Chrome DevTools
rob=Robot; % Create a Robot-object to do the key-pressing
rob.keyPress(KeyEvent.VK_F12)rob.keyRelease(KeyEvent.VK_F12)pause(2);% move mouse cursor to where you want
mouse = Robot;mouse.mouseMove(80,550); % pixel position on your screen. modify accordingly.
pause(1);% right click to show menu
mouse.mousePress(InputEvent.BUTTON3_MASK);pause(0.5);mouse.mouseRelease(InputEvent.BUTTON3_MASK);% move a little bit to activate second-level menu
for i=1:16 mouse.mouseMove(174+i,300); % modify accordingly
pause(0.0001);endpause(2);% move the cursor to the second-level menu
for i=1:6 mouse.mouseMove(359+i,335); % modify accordingly pause(0.0001);endpause(2);% left click to do copy
mouse.mousePress(InputEvent.BUTTON2_MASK); %left click press
pause(0.5);mouse.mouseRelease(InputEvent.BUTTON2_MASK); %left click release
% load the copied text into Matlab workspace
str=clipboard('paste');
To my experience, It might fail sometimes. So, not efficient, but hope it is helpful.
Acknowledgements :
There is a popen() in the File Exchange that can be used in Linux and OS-X . It does not support bidirectional transfers, but if you do not need to analyze the responses then you should be okay by just redirecting the output to a file (and possibly reading the file afterwards.)
On the other hand, if it is just a matter of sending input to a command line program without needing to interact with it, then there is a much easier way: write all of the desired commands into a file, and then when you system() redirect standard input from the file.
Best Answer