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:
  1. Has this behavior changed intentionally in R2025a? I can't find anything on this in the change log. Or is this maybe a bug?
  2. 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
  2 个评论
Michael Liedlgruber
Since I found also other inconsistencies regarding the event data, I just filed a bug report.
Michael Liedlgruber
Brief update: after filing a bug report, it seems like the problem event exists in R2024b when the new desktop is enabled. So this seems be related to the new desktop system.

请先登录,再进行评论。

回答(1 个)

Satwik
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!
  1 个评论
Michael Liedlgruber

Thank you. Yes, you‘re right. In the meanwhile I got the same answer from Mathworks support. And I also found that page already. But there are two flaws in the documentation. First, I‘m using the figure function and not the uifigure function to create my figure. So I didn‘t assume that this also applies to my problem. And, second, the documentation is a bit unclear here. It states „… event data can return …“. To me this means that is is possible. So, in my opinion the documentation should be more clear here.

And it‘s a matter of fact that Mathworks missed to document these changes somewhere (e.g. the changed codes for the arrow keys). So Mathworks told me that they filed an internal request to improve the documentation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by