フィルターのクリア

How detect the mouse PRESS of a pushbutton?

3 ビュー (過去 30 日間)
Anthony Poulin
Anthony Poulin 2012 年 11 月 5 日
編集済み: Walter Roberson 2021 年 4 月 19 日
Hi,
I am currently working on a GUI and I need to detect the left mouse press (and release) of a pushbutton. Then I associate a callback for each event detected. For example: I Want to set a variable to 1 at the mouse press and to 0 at the mouse release.
I have allready explore: - UIcontrol 'Callback' property but it is active at the release mouse click.
- UIcontrol 'ButtonDownFcn' property which is active at the mouse press click but only with right mouse button or on 5-pixel border around the uicontrol).
- On the file exchange a function which allow to put Java's properties on uicontrol but it's very time consuming (1 minute for launching my GUI).
I want the two figure's properties 'WindowButtonDownFcn','WindowButtonUpFcn' but for a uicontrol (pushbutton).
If you execute the code below you can see at the mouse press, 'press' displaying in the console window and at the mouse release you can see 'release' in the console.
figure('WindowButtonDownFcn',@(obj,evt)disp('press'),...
'WindowButtonUpFcn',@(obj,evt)disp('release'));
I'm writting because I have no other idea to do this... So if anyone knows a way to help me, I would be very grateful!!

採用された回答

Anthony Poulin
Anthony Poulin 2013 年 4 月 4 日
I find answer to my question using Java command which is recognized by matlab.
  1 件のコメント
kurguz
kurguz 2013 年 5 月 29 日
Anthony, how did you do that? I have the same problem now and I have no idea how to integrate Java in my code.

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

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 11 月 5 日
You use the WindowButton* callbacks and have them detect whether they are over the control area or not.
  1 件のコメント
Anthony Poulin
Anthony Poulin 2012 年 11 月 7 日
Sorry, but I don't understand your answer.

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


Jan
Jan 2012 年 11 月 7 日
編集済み: Walter Roberson 2021 年 4 月 19 日
You have written already:
figure('WindowButtonDownFcn', @(obj,evt)disp('press'),...
'WindowButtonUpFcn', @(obj,evt)disp('release'));
Create a toggle-button and disable it: 'Enable', 'inactive'. Now use a callback function in the figure instead of the code to display string. Then test in this function, if the mouse is over the uicontrol: Either overobj() or check the 'CurrentPoint' property of the figure and compare it with the uicontrol position. Now call a function only, if the mouse is clicked over the button and modify the buttons 'Value' accordingly to geta visible reatcion.
  3 件のコメント
Anthony Poulin
Anthony Poulin 2012 年 11 月 8 日
I developp this GUI for a client, and I think that using a toggle button (more over which is enable) is not intuitive for my application and my client.
Jan, I think your method doesn't work because in this case the mouse press is detected and launch the callback but the mouse release is not detected so the others callback is not launch.
I just want to know, if there is a way in matlab to detect a mouse pressed and released on a pushbutton.
Jan
Jan 2013 年 4 月 5 日
Yes, it should be overobj. And the mouse-release is detected by the WindowsButtonUpFcn and can be handled there.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by