Figure 上でマウスの左/右クリックを識別し、別々のコールバックを設定するにはどうすればよいですか?
14 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2017 年 3 月 8 日
回答済み: MathWorks Support Team
2017 年 3 月 8 日
Figure 上の座標軸上で、マウスを左クリックしたときと、右クリックしたときで、異なるコールバック処理を行う方法を教えてください。
採用された回答
MathWorks Support Team
2018 年 3 月 9 日
Figure の SelectionType プロパティの値によって、Figure が選択されたときのマウスクリックの種類を識別することができます。
Figure の SelectionType プロパティの詳細については、以下の URL よりヘルプドキュメントをご覧ください。
・MATLAB ヘルプドキュメント:Figure プロパティ
https://jp.mathworks.com/help/matlab/ref/figure-properties.html#property_SelectionType
以下の例では、Axes の ButtonDownFcn コールバックを用いて、左クリックと右クリックを識別するプログラム(myGUI.m)です。
% myGUI.m
function myGUI
figure;
plot(1:10)
ax = gca;
% Axes の ButtonDownFcnコールバックを設定
set(ax,'ButtonDownFcn', @mybdfun)
function mybdfun(src,eventdata)
% ButtonDownCallBack の内容
h = get(src,'Parent'); % Axes の親オブジェクト= Figure のハンドル取得
Stype = get(h, 'SelectionType');
% クリックの種類を判別
if strcmp(Stype,'normal') % 左クリック
disp('Left Click')
elseif strcmp(Stype,'alt') % 右クリック
disp('Right Click')
end
end
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で 対話型コントロールとコールバック についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!