检测键盘输入Matlab [英] Detect Keyboard Input Matlab

查看:1065
本文介绍了检测键盘输入Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题,尽管它比看起来要难.我在互联网上找不到答案:O

I have a simple question, although it's harder than it seems; I couldn't find the answer on the interwebs :O

我正在用Matlab编写脚本.我想做的是以下事情:

I'm writing a script in Matlab. What I want to do is the following:

  • 当我按下esc键时,我希望弹出一个帮助对话,因此我的脚本暂停. (因此,当我按esc键时,我要停止运行整个脚本,以使汽车(正在为其编写脚本的车辆)停止行驶)

我该怎么做?我该如何对Matlab说:当我按esc键时,请执行此操作...

How do I do this? How can I say to Matlab: When I press esc, do this...

感谢您的陪伴!

不能执行等待按键的操作.我正在为驾驶汽车编写脚本.它只需要基本行驶,但是例如当我按esc键时,它应该停止行驶.这样脚本就必须运行,直到我按esc键为止.那么脚本必须暂停.

It's no option to implement something which awaits the keypress. Im writing a script for a driving car. It just has to drive around basically, but when I press esc for example, it should stop driving. So the script just has to run, untill I press the esc key; then the script has to pause.

推荐答案

在matlab图中,您可以定义一个'KeyPressFcn',其作用与您要执行的操作类似.

In a matlab figure you can define a 'KeyPressFcn' that works similar to do what you ask.

如果您在控制台中,则必须解决该Matlab是单线程的问题.基本上,您需要停止程序流以检查按键.

If you are in the console you have to work around that matlab is single threaded. Basically you need to halt the program flow to check for key presses.

顺便说一句-同样,当您使用'KeyPressFcn'时,您也需要暂停一下,以便Matlab检查是否发生了任何事情.

btw - also when you use 'KeyPressFcn' you will need to make some pauses so that Matlab will check if anything has happened.

btw2-我还应该在此暂停期间添加Matlab,不仅会读取您的按键-还会做一些内务处理,例如重绘其窗口和内容.

btw2 - I should also add during this pauses Matlab will not only read your key presses - but also do some housekeeping such as redrawing its window and stuff.

这篇关于检测键盘输入Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆