determine if the mouse is pressed in a given moment
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I’m wondering if the Figure class has some (probably hidden) property that expresses if the mouse is pressed (and which button) in the moment that the moment that the property is read. If the figure had an event for button up and down events that would also solve my problem.
I know I could set WindowButtonDownFcn and WindowButtonUpFcn to inform a global variable to keep track on when the mouse is used, but that's deeply unpractical (in my code WindowButtonDownFcn gets changed frequently depending on the actions of the user)
0 commentaires
Réponse acceptée
Jan
le 19 Sep 2017
Modifié(e) : Jan
le 19 Sep 2017
It would be easy, if you do not change the WindowButtonDownFcn frequently, but keep it statically and use a persistent variable for branching. Then you had to insert the code to store the button state at one location only.
If you check the button state, you have to consider the currently active window also. You do not want to react to clicks in the task bar or the desktop.
What about https://www.mathworks.com/matlabcentral/fileexchange/61976-check-if-mouse-button-is-pressed under Windows?
[EDITED] The FEX submission is not working out of the box. Try this:
% !!! UNTESTED !!!
function [L, R, M] = GetMouseKeyStatus()
if ~ispc
error('Running under Windows only.');
end
if ~libisloaded('user32')
loadlibrary('user32.dll', 'user32.h');
end
L = calllib('user32', 'GetAsyncKeyState', int32(1)) ~= 0;
R = calllib('user32', 'GetAsyncKeyState', int32(2)) ~= 0;
M = calllib('user32', 'GetAsyncKeyState', int32(4)) ~= 0;
end
20 commentaires
Matthieu
le 12 Déc 2023
Modifié(e) : Matthieu
le 12 Déc 2023
Hi,
my variable 'perlInst' contains exactly the same as you.
Your cmdString is similar, containing also :
%PATH%&perl "C:\Program Files\MATLAB\R2023b\toolbox\matlab\general\private\prototypes.pl"
and this is identical also : &set PATH=C:\Program Files\MATLAB\R2023b\sys\perl\win32\bin\;
Finally a REBOOT (!) of my computer finally solved the problem, incredible !! ?? ...
BUT : I then removed the environnement variable PATH to 'C:\Program Files\MATLAB\R2023b\sys\perl\win32\bin\' and reboot Matlab and ismousedpressed.m is NOT working anymore...
So I recreated this PATH entry in the environnement variable : C:\Program Files\MATLAB\R2023b\sys\perl\win32\bin\, reboot MATLAB again and ismousedpressed.m is working again !!
So it seems that perl.exe was not reachable by Matlab as DOS command and it seems that PATH of environnement variables are loaded at Matlab startup (?).
Thanks for your help Bruno !
Bruno Luong
le 12 Déc 2023
For sure the PATH is loaded at the MATLAB startup (or in general any windows program). What I don't understand is that the system commannd in perl.m use the full absolute path, and why it needs the path environment?
Anyway glad you solve the issue.
Plus de réponses (1)
Ankit Bhardwaj
le 24 Avr 2017
Modifié(e) : Ankit Bhardwaj
le 24 Avr 2017
You can use ButtonDownFcn callback for your figure. This callback executes whenever the user clicks a mouse button while the pointer is in the figure window, but not over a child object such as a uicontrol, uipanel, axes, or axes child. Moreover, mouse selection type returns 'normal', 'extend' , 'alt' , or 'open'. MATLAB maintains this property to provide information about the last mouse-button press that occurred within the figure window. This information indicates the type of selection made. Please go through the following documentation to learn about callback properties of figure object.
https://www.mathworks.com/help/matlab/ref/figure-properties.html#zmw57dd0e274973
2 commentaires
Voir également
Catégories
En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!