Search code examples
matlabkeyboardcharacter

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. Could somebody give me an example? I have tried to use get(gcf,'CurrentCharacter');


Solution

  • From MATLAB documentation:

    CurrentCharacter
    

    single character

    Last key pressed. MATLAB sets this property to the last key pressed in the figure window. Use CurrentCharacter to obtain user input.

    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)
    3. Type a character (it will likely appear in your command window)
    4. Enter kkey = get(gcf,'CurrentCharacter') in your command window

    By doing this you set kkey to the first character you typed while your figure window was active.