How to determine the coordinates of mouse pointer after a mouse click event.
이전 댓글 표시
I have written a rather rudimentary function to automate an external software GUI by use of the java robot
Example:
robot.mouseMove(coordinates(1,1),coordinates(1,2));
robot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
The software that I am using this function to automate is antiquated and requires the user to click through several settings and tabs within the GUI each time he/she wants to run the software. The function works wonderfully on my computer without any hiccups but I know that my mouseMove locations are unique to my monitor and will differ for another computer.
I am looking for a way to capture the location of the mouse pointer by using mouse clicks as an event (i.e., user clicks the mouse and Matlab retains the pixel coordinates). This way I can create a "setup file" for each user to run the first time they run the function. I currently am using coordinates(n,1:2)=get(0,’PointerLocation’) but I need to know if there is a way to tie this to a mouse click event.
An idea of what I am looking for:
n=0
MouseClickEvent toggles below code:
n=n+1;
coordinates(n,1:2)=get(0,’PointerLocation’)
Any advice is appreciated and I thank you in advance!
채택된 답변
추가 답변 (1개)
William Leath
2018년 2월 13일
Here is an alternate way to get mouse click coordinates outside of figure or frame constraints:
build an executable (I used MinGW g++):
C:\"Program Files (x86)"\CodeBlocks\MinGW\bin\g++.exe -c mouse_loc.cpp
C:\"Program Files (x86)"\CodeBlocks\MinGW\bin\g++.exe -o mouse_loc mouse_loc.o
from the following (mouse_loc.cpp) source code:
----------------------------------------------------------------------------------------------------
#define WINVER 0x500
#include<windows.h>
#include<stdio.h>
int main()
{
GetAsyncKeyState(VK_LBUTTON); /** clears buffer **/
POINT pos;
while (GetAsyncKeyState(VK_LBUTTON)==0) {Sleep(15);}
GetCursorPos(&pos);
printf("%i, %i", pos.x, pos.y);
return 0;
}
--------------------------------------------------------------------------------------------------
call it from Matlab using either a DOS or system call:
[status,mloc]=dos('mouse_loc');
pause(0.05);
loc=str2num(mloc);
카테고리
도움말 센터 및 File Exchange에서 Desktop에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!