Have some keypress character codes changed in R2025a?
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I recently noticed that in R2025a some keypress character codes obviously changed as compared to previous versions. In my code I want react to pressed arrow keys in a figure. In older versions the character codes passed into a keypress callback or returned by get(gcf, 'CurrentCharacter') were
- Left arrow: 28
- Right arrow: 29
- Up arrow: 30
- Down arrow: 31
In R2025a, however, the codes returned seem to be UTF-16 values:
- Left arrow: 8592
- Right arrow: 8594
- Up arrow: 8593
- Down arrow: 8595
The following code allows to verify this:
function testKeyPress()
figure('Name', 'Keypress Test', ...
'KeyPressFcn', @(src, event) keyPressCallback(src, event));
function keyPressCallback(src, event)
fprintf('Key: %s Character: %d Figure CurrentCharacter: %d\n', ...
event.Key, double(event.Character), double(get(src,'CurrentCharacter')));
I know that I could use the field "Key" in case of a callback to get the string representation for an arrow key (e.g. leftarrow). But this doesn't work in case of the CurrentCharater property of a figure, which I need in my code.
So my questions are:
- Has this behavior changed intentionally in R2025a? I can't find anything on this in the change log. Or is this maybe a bug?
- If the new behavior is not a bug, is there any way to get the codes as returned by the old versions of MATLAB from the UTF-16 value? I know that I could just solve this using a switch-statement and test for the different cases. But I'm wondering if there is a more generic solution, probably working for other key codes too which may have changed as well?
Best,
Michael
回答(1 个)
Satwik
2025-7-18
I found the following information in MATLAB Release Notes for R2024a release:
The 'Character' property of the key-press callback event data can return an expanded set of keys using the Unicode® symbol for the pressed key. This change provides key data for a larger set of keyboard keys across many writing systems.
Additionally, to my knowledge the older values of 28-31 for arrow keys were incorrect, since arrow keys do not have ASCII codes.
I hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!