How can I do a shortcut with the up and down arrow to change the value by one of the Edit numeric field?
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2022-3-24
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.
回答(1 个)
Ravi
2023-10-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!