Borrar filtros
Borrar filtros

Mouse Button Press distinction

50 visualizaciones (últimos 30 días)
Khalid Mahmood
Khalid Mahmood el 15 de Abr. de 2021
Respondida: Jixiong Su el 1 de Nov. de 2023
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 comentarios
Khalid Mahmood
Khalid Mahmood el 15 de Abr. de 2021
I used WindowKeyPressFcn and WindowKeyRelease fcn in parallel to WindowButtonDownFcn and I am able to distinguish all combinations of modifiers and mouse buttons.
In WindowKeyPressFcn(src,evt) I just set a flag (ModifierPresent=true) and ModifierName=evt.Key.
In WindowKeyReleaseFcn(src,evt) I just set a flag (ModifierPresent=false) and ModifierName=' '.
In WindowButtonDownFcn I query(src,'SelectionType') and check if(ModifierPresent) then ModifierName tells which modifier is used...
Is there any simple way?
Khalid Mahmood
Khalid Mahmood el 17 de Abr. de 2021
Editada: Khalid Mahmood el 19 de Abr. de 2021
Ooooch,
  1. I forgot that my pupose was to distinguish between CTRL+LeftClick and CTRL+RightClick. Which still remains the issue
  2. I was able to use evt.Key for Keyboard keys and Modifiers (evt.Modifier) using WindowKeyPress/Release functions, which can't be done using WindowButtonDown/Up functions for all keys
Can anybody help me to distinguish between CTRL+Left Mouse Button Click and Ctrl+ Right Mouse Button Click. My code is attached

Iniciar sesión para comentar.

Respuestas (2)

Sufia Tanveer
Sufia Tanveer el 19 de Abr. de 2021
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 comentario
Khalid Mahmood
Khalid Mahmood el 19 de Abr. de 2021
I accept your answer, but I am waiting for some senior programmer or matlab staff members to answer to be precise

Iniciar sesión para comentar.


Jixiong Su
Jixiong Su el 1 de Nov. de 2023
distinguish between Ctrl+click and click
fig = uifigure();
Error using matlab.internal.lang.capability.Capability.require
This functionality is not available on remote platforms.

Error in matlab.ui.internal.uifigureImpl (line 32)
Capability.require(Capability.WebWindow);

Error in uifigure (line 34)
window = matlab.ui.internal.uifigureImpl(varargin{:});
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

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by