How to read mouse position in figure when mouse is static/not moving

2 views (last 30 days)
I am currently using the function: set (gcf, 'WindowButtonMotionFcn', @mouseMoveCircle); where mouseMoveCircle is a custom code which spits out tones/sound based on mouse position in figure. However, if the mouse is not moved, then I want the last played (based on mouse location) to continue playing till mouse is moved again. However, I am unable to figure out now how to figure out if the mouse has been static... Any help will be appreciated...

Accepted Answer

stormchaser88
stormchaser88 on 16 Apr 2012
Hi walter, the problem is that mouseMoveCircle is called only when the mouse is moved....that is a drawback of the Set(gcf...) command...maybe I should use something else? Jan, persistent might make sense, I ll try it out....for now I guess using different forms of the get, set commands might do the trick??

More Answers (2)

Walter Roberson
Walter Roberson on 14 Apr 2012
In your mouseMoveCircle, increment a shared variable each time it is called. Then in your other code, if the shared variable is the same as it was last time you checked, then the pointer is static.
  3 Comments
stormchaser88
stormchaser88 on 2 May 2012
Thanks Walter for the input....One issue that I am facing still is that when I try to play the sound based on mouse movements, matlab usually freezes up , as in, it slows down a TON.....is that due to matlab's lack of real time capabilities? I am use playblocking to play the soumd....
Walter Roberson
Walter Roberson on 2 May 2012
Blocking play is not going to pay attention to mouse interrupts until the sound ends.
You should be periodically queuing a set of samples for the player, and (if possible) play the sound non-blocking; near the end of each set you would queue more samples based upon the current state. MATLAB does not provide good facilities for this with the standard windows sound device.
In order to do this kind of work you are much better off using a D/A convertor that you can queue samples for, such as via the Data Acquisition toolbox.

Sign in to comment.


Jan
Jan on 14 Apr 2012
I assume using a timer and a persistent variable will help.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!