Mouse Button Press distinction between "Left Mouse Button" and "Double Click Button"

17 ビュー (過去 30 日間)
Vinay JR
Vinay JR 2023 年 2 月 14 日
回答済み: Sai Teja G 2023 年 8 月 29 日
I have a Figure on which I load an .png image. I need to distinguish between SelectionType: "Left click" and "Double click". Below is my program. As I run it, when ever a Double click is excecuted it displays a "Left click". How do I make the program identify a "Double click"?
figure(1)
im= imread('Mouse.PNG'); %loading the image
i=imshow(im);
set(i,'buttondownfcn',@mybttnfcn); %setting the callback function
function mybttnfcn(h,~)
haxes = get(h,'parent'); %axes properties
hfigure = get(haxes,'parent'); %figure properties
b = get(hfigure,'selectiontype'); %identifying Selectiontype
xy = get(gca,'CurrentPoint'); %getting current points
if strcmpi(b,'normal')
text(xy(1,1),xy(1,2),'Left click') %displaying Left-click
elseif strcmp(b,'extend')
text(xy(1,1),xy(1,2),' Middle button') %displaying Middle-click
elseif strcmpi(b,'alt')
text(xy(1,1),xy(1,2),'Right click') %displaying Right-click
elseif strcmpi(b,'open')
text(xy(1,1),xy(1,2),'Double-click') %displaying Double-click
else
text(xy(1,1),xy(1,2),'Retry')
end
end

採用された回答

Sai Teja G
Sai Teja G 2023 年 8 月 29 日
Hi Vinay,
I understand that you want to identify the type of click the user does in the AppDesigner.
Unfortunately, it is currently not possible to identify left or right clicks in AppDesigner. However, there are workarounds available to detect double clicks.
  1. One approach is to use the 'WindowButtonDownFcn' function. You can refer to the following link for more details: WindowButtonDownFcn
  2. Another option is to use the 'WaitForButtonPress' function. You can write code similar to the example below to detect a double click:
w=waitforbuttonpress;
if w==0 % checking for single click
k=waitforbuttonpress;
if k==0 % checking for double click
disp("Hello World")
end
end
For more detailed documentation on both methods, you can refer to this link:
Hope it helps!

その他の回答 (1 件)

Tushar
Tushar 2023 年 2 月 20 日
Hi,
1. You can add a delay to distinguish single click from a double click, as your double clicks were perceived as two times single click.
You can have a look at this answer, which solves the same issue which you are facing:
2. But, if you even don't want to burn half-second each time, then you could add a click threshold, and take action on single or double type of clicks.
For this you can have a look here:
Hope it helps!
  1 件のコメント
Vinay JR
Vinay JR 2023 年 4 月 26 日
On an app made with APP Designer, I have a Button . Now i need to identify when a user do "left click", "right click" and "double click" on this button. How can I impelemnt this??

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by