How can I do a shortcut with the up and down arrow to change the value by one of the Edit numeric field?
4 views (last 30 days)
Show older comments
I'm doing a GUI and I want to change the value with the keyboard by using this code and making a callback of WindowsKeyReleaseFnc but I also used the KeyPressFcn and know it changes double, and instead of changing just one field it changes every field selected with the KeyPressFcn and I dont know yet how can I remove it.
key = event.Key;
value = app.Ibias_SH.Value
if strcmp(key,'downarrow')
value=value-1;
if value<0
value=12
end
elseif strcmp(key,'uparrow')
value=value+1;
if value>12
value=0;
end
end
app.Ibias_SH.Value = value;
Thanks
1 Comment
Rik
on 24 Mar 2022
So you have this code both in the WindowsKeyReleaseFnc and in the KeyPressFcn? Why not have it in 1 place?
Your question is not very clear to me.
Answers (1)
Ravi
on 10 Oct 2023
Hi IGNACIO SERRANO SANCHEZ-YBARGUEN,
If you want multiple EditField values to be changed when pressing the up and down arrows, create a keypress callback function in AppDesigner. Include all those EditField entries whose values are to be changed.
function UIFigureKeyPress(app, event)
key = event.Key;
value = app.CounterEditField.Value;
value1 = app.Counter1EditField.Value;
if ~strcmp(key, 'uparrow')
value = value - 1;
value1 = value1 - 1;
elseif ~strcmp(key, 'downarrow')
value = value + 1;
value1 = value1 + 1;
end
app.CounterEditField.Value = value;
app.Counter1EditField.Value = value1;
end
In the above code, the keypress callback is applied to two EditField values (CounterEditField, Counter1EditField). When an up arrow is pressed, the value in both the edit fields get incremented and when a down arrow is pressed, the value gets decremented.
If you want to change the value by 1 but specific to only one EditField at a given instance of time, then I suggest you use a Spinner component instead of an EditField. In a Spinner component, you can increment and decrement the value by clicking on the component in the app without explicitly creating any callback functions.
Hope this helps.
0 Comments
See Also
Categories
Find more on Environment and Settings 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!