How can I do a shortcut with the up and down arrow to change the value by one of the Edit numeric field?
조회 수: 4 (최근 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에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!