KeyPressFcn in Matlabs App Designer - matlab

Hey there great ppl out there!
I have a rather simple problem but no idea how to solve it. 2h Google search didn´t help.
I´m getting hands on Matlab´s App Designer.
To keep it simple: I have a button and a numerical field. Every time I click the button - a callback is called increasing the value of the numerical field by 1.
How can I implement a KeyPress event?!? I.e. When I press the '+' Key on my keyboard I would like to trigger the callback fuction of the button (or if not possible any other function).
I´m pretty sure the developers of App Designer must have thought about this - but I´m simply to untalented to find the right documentation. I think in GUIDE there´s something called 'keypressfcn' - so I basically need an equivalent for the App Designer.
Please help :)
Increasing the Number field by 1 when hitting the button or pressing the '+' key on my keyboard

A KeyPressFcn has been added as of Matlab R2019a. In appdesigner click the Callback button, select your figure, then choose the callback 'KeyPress'. I got it to work. More info here: https://www.mathworks.com/help/matlab/ref/matlab.ui.figureappd-properties.html

Related

(MATLAB, App Designer) How can I write a callback function for Sine Button?

The first screenshot is the frontend of project.
The second screenshot is a specific portion of the backend of the project.
The screenshots are as links.
The aim of this question is that whenever I press the sin function and assign to it a value (Example: Sin(45)), I want the calculator to calculate that value.
Can someone please guide me regarding this issue?

Property additionalActions of NSUserNotification seems not working?

To understand NSUserNotification better, I wrote a little test app playing with this class.
So far so good, except that no matter how hard I tried to feed the additionalActions property with array of NSUserNotificationAction objects, it never showed any difference but only one action button and a close one.
My expectation for this property is that the notification would show a pull-down menu containing the additional buttons I offer as it does in the Mac App Store update notifications.
Am I missing something? Or are you having the same problem, since it is a bug awaiting Apple to tackle?
Can you please try to click and hold down the action button in your notification? Does it show a drop-down menu of additionalActions?
Update
As it turns out, you can show the little chevron next to the action button by setting a true value for the private _alwaysShowAlternateActionMenu key on the notification. In Swift 3, it would look like this:
notification.setValue(true, forKey: "_alwaysShowAlternateActionMenu")
However, as I mentioned this is a private API and I strongly advise against using it if you want to distribute your App through the Mac App Store.
It is probably a bug. Setting up additionalActions will create the list, but not the little arrow icon. Holding down on actionButton will show the menu with the number of actions you set.
Besides setting additionalActions will cause several other problems. I will save this for another question.
Refer to another question.
show NSUserNotification additionalActions on click
P.S. I am using El Capitan APIs

Enabling and Disabling GUI button Matlab

This is a very strange problem, because I am quite sure the logic is proper but it is still not working. So when the GUI starts, in the starting function, I set most of the buttons to be inactivated using the following line of code for every button, Kbutton, Bbutton etc..:
set(handles.Kbutton,'Enable','off');
set(handles.Bbutton,'Enable','off');
Then, when the user clicks on any cell in the uitable, I use the cell selection callback to get the info about the contents of the cell, and re-activate the buttons that can be used from then on:
set(handles.Kbutton,'Enable','on');
set(handles.Bbutton,'Enable','on');
And till now everything is ok.
So then the user clicks on a button, say Kbutton, and the underlying function is executed thanks to the button's callback function. Once the method is ready I would like to return the buttons to their initial state i.e. inactivated. So logic tells me, re-put the initial line of code at the end of the callback function and done:
set(hObject,'Enable','off');
drawnow;
set(handles.BButton,'Enable','off');
drawnow;
Where the first line of code in the above snippet, refers to the button who fired the callback and BButton is any other button in the GUI.
For some strange reason only the second one is being enabled off. I.e. the button that fired the callback is staying enabled on :/
Has anyone encountered the same problem?
Any ideas?
Thanks in advance
Try changing
set(hObject,'Enable','off');
to
set(handles.Kbutton,'Enable','off');
You click on tools =>gui options =>Generate FlG file and MATLAB file

Keys pressed - Swift

I am trying to run some code when the user presses the space bar, does anyone know how to do this? Key codes would be helpful. I am programming in Swift an using SpriteKit
Well using google you can search for lists or images of keyboards with the listed keycodes, however I suggest using problem solving for when something like that isn't available. When the keyPress event is called, print the keycode that was pressed. This way, you can press the space bar and it will tell you what the keycode of it was without having to rely on outside sources.

MATLAB - callback excecution of edit box

As it is referenced in MATLAB documentation for edit box uicontrol or stated in this
post, when another component or menu bar or background GUI is clicked, the edit box callback gets executed. But in my attempts to use this functionality, I haven't been able so far to see the callback execution unless there is a change of edit box text or Enter key is pressed. What I'm trying to achieve is to execute edit box callback whenever there is focus loss from edit box even when nothing has been entered. Please enlighten me about what I'm missing here and how I can do this?
Thanks in advance.
The underlying Java object has a callback called FocusLostCallback that'll do what you want - execute when the object's focus is lost, even if you changed nothing.
You'll need findjobj from the MATLAB File Exchange. Then, get the Java handle and set the callback as usual (make sure the uicontrol is visible when you try to get the Java handle):
jh = findjobj(myEditBox); % myEditBox is a uicontrol handle
set(jh, 'FocusLostCallback', #myCallback);
A more complete list of the undocumented uicontrol callbacks can be found at Yair Altman's Undocumented MATLAB blog.
This method work perfectly with single-line textbox, but it has any effect with multi-line textbox (uicontrol, style edit, max = 2)