Mouse Button Press distinction
์ด์ ๋๊ธ ํ์
SelectionType property of figure tells which mouse button was pressed along with modifier (ctrl or shift).
Normal: Left Mouse Button.
extend: i) Shift+LeftMouseButton OR ii) Middle Mouse Button OR iii) Both Left and Right Buttons
alt: i) CTRL+LeftMouseButton OR ii) Right Mouse button
open: Double Click Any Mouse Button.
1: Why CTRL+LeftMouseButton and CTRL+RightMouseButton return same code in mouse events? Its only in Matlab.
2: I want to distinguish between CTRL+LeftMouseButton and CTRL+RightMouseButton. How to do this?
๋๊ธ ์: 2
Khalid Mahmood
2021๋
4์ 15์ผ
Khalid Mahmood
2021๋
4์ 17์ผ
ํธ์ง: Khalid Mahmood
2021๋
4์ 19์ผ
๋ต๋ณ (2๊ฐ)
Sufia Tanveer
2021๋
4์ 19์ผ
1 ๊ฐ ์ถ์ฒ
I have tested your code. Your code is great work. Matlab developers have somehow missed that distinction of modifier + right mouse button. I have searched help and found you are ๐ฏ% correct. What I can say is, it may have not been rectified by developers. That's why nobody else has given you answer.
๋๊ธ ์: 1
Khalid Mahmood
2021๋
4์ 19์ผ
distinguish between Ctrl+click and click
fig = uifigure();
fig.WindowButtonDownFcn = @figureClickCallback;
fig.KeyPressFcn = @figureKeyPressCallback;
fig.KeyReleaseFcn = @figureKeyReleaseCallback;
fig.UserData.CtrlPressed = false;
function figureClickCallback(src, ~)
if strcmp(src.SelectionType, 'alt') && src.UserData.CtrlPressed
% Ctrl + Left Click
disp('Ctrl + Left Click');
elseif strcmp(src.SelectionType, 'normal')
% Left Click
disp('Left Click');
% Right Click
elseif strcmp(src.SelectionType, 'alt')
disp('Right Click');
end
end
function figureKeyPressCallback(src, event)
if strcmp(event.Key, 'control')
src.UserData.CtrlPressed = true;
end
end
function figureKeyReleaseCallback(src, event)
if strcmp(event.Key, 'control')
src.UserData.CtrlPressed = false;
end
end
์นดํ ๊ณ ๋ฆฌ
๋์๋ง ์ผํฐ ๋ฐ File Exchange์์ Update figure-Based Apps์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!