Mouse as interrupt - matlab

I am using MATLAB Psychtoolbox for understanding behaviour of human under critical condition.
I want to use mouse as an interrupt. To be more precise, a program is running and a mouse action is needed when an abnormality happens.Since presence of abnormality is not well defined so does the operator action. So I need to be always of action taken by human. How to keep track of human action with mouse??
Please help!!!

Do you want just mouse clicks or all mouse movement? For the former, you can just use the function waitforbuttonpress. Otherwise, if you need coordinates for example, you would use the ginput function.

I think you need to set the 'ButtonDownFcn' to your figure.
Have a look at this.

Related

Pure Data MIDI Toggle Switch

I am looking to build a tool that allows me to toggle on/off certain GEMheads in my patch based on MIDI pad input. Pressing one pad would turn on a render chain and pressing a different pad would activate a new render chain. Pressing the midi pad for any active render chain should disable the rendering.
I'm having quite some trouble building this into my current patches which look like this:
pad_control
template
I grab the MIDI identity and use it to generate a one or a zero, however I'm not certain of the logic to keep the output as a 1 when pressing different MIDI pads and how to add the toggle functionality. As of now, only one can be active at any given time.
Any help is appreciated, thank you!
I think that's basically what you are after, the toggle representing the MIDI pad. The change object is only there to protect for cases like with a keyboard, where repeated strokes are sent, probably not necessary for a MIDI pad, but doesn't hurt either.
For those wondering, this is what my solution looks like tuned specifically to my MIDI settings
controller_1
Hope this helps anyone else!

GTK prevent custom widget from grabbing focus

I've implemented a musical keyboard as a subclass of Fixed and where each individual key is a subclass of DrawingArea, and so far, it works great: custom drawing code in expose, press+release functionality working... kind of. See, here's the problem: I want the user to be able to drag the mouse across the keyboard with the mouse down to play it. I currently capture the button press and release signals, as well as enter and leave notify. Unfortunately, this doesn't quite work because the widget seems to grab focus of the mouse as soon as the mouse is pressed over it. This makes sense for normal buttons, but not for a musical keyboard. Is there any good way to remedy this other than rewriting the entire keyboard to be one massive DrawingArea?
Also, it shouldn't matter, but in case it does I'm using GTK#.
You might consider using GooCanvas: You can represent each of the keys as CanvasPolylines, fill them with the colors you need. Each of the Canvas items is a GtkWidget, so you can act on events like enter, leave, button-pressed etc.
This method seems to make more sense (to me) than separate DrawingAreas. As each drawn element is still accessible, you can even change colors/size and other properties dynamically. Also, Polyline lets you make more complex shapes.

How to free draw and erase on a MATLAB GUI?

I wanted to create a gui that worked as a canvas for free drawing lines with the mouse and with option of erasing...
anyone can help me?
The simplest solution is to look at how other people have implemented this. For example, searching for freehand on the File Exchange brings up this freehand drawing function.
As a basic idea, you'll want to either regularly capture the mouse position, or to evaluate a callback on mouse movement.

Matlab: How to stop a spinning plot programmatically when the camera is in orbit mode

To see what I mean excatly please:
Run the code below
figure
plot(peaks)
cameratoolbar('SetMode','orbit');
cameratoolbar('Show');
Move mouse onto the plot. Hold down the left click, move the mouse to left ot right then release the click. You'll see the plot start sniping for ever.
Now if you click on the red, stop sign button it stops from spinning. However I would like to programmatically stop the spinning plot. Any thoughts?
Opening cameratoolbar in the editor reveals that orbiting is accomplished by setting the figure's WindowButton* callbacks temporarily to nested/sub functions within cameratoolbar.
Judging from the 1-minute diagonal read-through I did, the camera orbit itself is accomplished by calling a pan/zoom function orbitPangca, which recursively calls cameratoolbar. This recursion loop is controlled by flags which are toggled by the callbacks from the toolbar buttons. These flags alter the behaviour of each iteration in the recursion loop.
If this is indeed the case, it would imply that Matlab is not accepting commands from any source you have programmatic control over, while the plot is orbiting. It'll only respond to the button presses. This means that if you want to stop the motion programmatically, you'd have to hack cameratoolbar to allow for this - not the most portable option.
Another idea that just popped to mind, is figuring out which WindowButton* callback is used for the orbit, and define your own function there. You might just be lucky enough that the MathWorks implemented cameratoolbar such that both callbacks are called each iteration, which would give you programatic control over the flags. But -- you'd have to test this yourself.

Mouse Handling in Matlab

Is there any way in matlab to do mouse event handling like click handling?
I need it to develop an application where I'm displaying an image in matlab's imshow.
Once user clicks at a particular point on image, I need to know co-ordinates of that point and use them for later processing.
To capture clicks, you have to define the ButtonDownFcn property of your IMAGE. The callback can then read the CurrentPoint property of the AXES and thus determine the coordinates.
Alternatively, you may want to have a look at GINPUT if you want the user to select a fixed number of points.