Step-by-step guide
1. Download mouse1.zip, and ready the files in a working folder of MATLAB.
2. Open gui_mouse.fig using GUIDE.
3. Add a static text to the GUI and rename its tag to lbl_last_action
4. Open the property window of the figure (double click on the figure), click on WindowButtonDownFcn to populate the callback and paste the following code:
pos = get(hObject, 'currentpoint'); % get mouse location on figure
x = pos(1); y = pos(2); % assign locations to x and y
set(handles.lbl_last_action, 'string', ['Mouse pressed @ X: ', num2str(x), ', Y: ', num2str(y)]);
pos = get(hObject, 'currentpoint'); % get mouse location on figure
x = pos(1); y = pos(2); % assign locations to x and y
set(handles.lbl_last_action, 'string', ['Mouse released @ X: ', num2str(x), ', Y: ', num2str(y)]);
Anytime when the mouse is pressed (down) or released (up), the text field is updated with the action and the location of the action. Note that if the button is released quickly after pressed, the text field may be updated too quickly as if there is no press action.
Video
Files:
Files can be downloaded here. Note some changes have been made to the GUI to make it more presentable.
No comments:
Post a Comment