How to get the last character pressed on the keyboard?

10 ビュー (過去 30 日間)
Mr M.
Mr M. 2018 年 3 月 14 日
コメント済み: Walter Roberson 2018 年 3 月 14 日
I dont want to wait to anything, just need to read out the last pressed key. Is it possible?

回答 (1 件)

Guillaume
Guillaume 2018 年 3 月 14 日
編集済み: Guillaume 2018 年 3 月 14 日
Neither matlab nor the OS keep a record of the key presses. If you don't capture it when it occurs, then it never happened.
If you're using a matlab GUI, you could detect all keypresses (while your GUI has focus) using the WindowKeyPressFcn callback and store the key pressed into a variable. Whatever last value was written in this variable would be the last key pressed.
If you want it to work without a GUI or want to track key pressed even when your GUI is not in focus, then you'll have to hook directly into your OS API most likely via a mex file. An exercice left to the reader... Again you'll have to actively capture the key presses and keep the last one on hand for when you need it.
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 14 日
If a figure is in focus then you can access its CurrentCharacter property.
If you do not have any figures at all then see Guillaume's answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by