简体   繁体   English

如何在Matlab中使用CurrentCharacter?

[英]How do I use CurrentCharacter in matlab?

I am trying to use the CurrentCharacter property in matlab but I don't know how it works. 我正在尝试在matlab中使用CurrentCharacter属性,但是我不知道它是如何工作的。 Could somebody give me an example? 有人可以给我一个例子吗? I have tried to use get(gcf,'CurrentCharacter'); 我尝试使用get(gcf,'CurrentCharacter');

Run this code and start pressing the keys on the keyboard. 运行此代码,然后开始按键盘上的键。 Observe the output on the Command Window. 观察命令窗口上的输出。

f = figure;
set(f, 'KeyPressFcn', @(x,y)disp(get(f,'CurrentCharacter')))

From MATLAB documentation: 从MATLAB文档中:

 CurrentCharacter 

single character 单字符

Last key pressed. 最后一个按键。 MATLAB sets this property to the last key pressed in the figure window. MATLAB将此属性设置为图形窗口中最后按下的键。 Use CurrentCharacter to obtain user input. 使用CurrentCharacter获取用户输入。

I'm not sure how you're intending to use it, but here's a simple way to demonstrate it;; 我不确定您打算如何使用它,但这是一种简单的演示方法;

  1. Create a figure 创建一个人物
  2. Click on the figure (bring it to front in the OS GUI) 单击该图(将其显示在OS GUI的前面)
  3. Type a character (it will likely appear in your command window) 输入一个字符(它可能会出现在您的命令窗口中)
  4. Enter kkey = get(gcf,'CurrentCharacter') in your command window 在命令窗口中输入kkey = get(gcf,'CurrentCharacter')

By doing this you set kkey to the first character you typed while your figure window was active. 这样,您可以将kkey设置为图形窗口处于活动状态时键入的第一个字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM