Clear Filters
Clear Filters

Problem using 'getkey'.

18 views (last 30 days)
Em_23 on 27 Sep 2015
For some reason 'getkey' is not working in Matlab R2014a. It keeps saying 'undefined function/variable' whenever I use getkey. Can anyone tell me what to do?
clear all;
fprintf('\nPress any key: ') ;
% prompt='Enter any key';
arduino=serial('COM15','BaudRate',9600); % create serial communication object on port COM15
fopen(arduino); % initiate arduino communication
fprintf(arduino,'%s',char(k)); % send answer variable content to arduino
answer=input('Enter value(0=EXIT PROGRAM): ');
fclose(arduino); % end communication with arduino

Accepted Answer

Geoff Hayes
Geoff Hayes on 27 Sep 2015
The error message
Undefined function or variable 'getkey'.
is telling you that MATLAB can't find the function getkey within the MATLAB search path. Is this a function that you have written or have downloaded from somewhere?
You may want to check the submission from Jos (10584) to the MATLAB File Exchange which can be found at You will need to download this code and place it within your MATLAB search path.
Em_23 on 28 Sep 2015
Thank you so much. It's working now!! :)
armando herculano
armando herculano on 2 Apr 2024
k=getkey, o que não é uma função padrão em MATLAB. Se você estiver tentando capturar a tecla pressionada pelo usuário, você pode usar a função pause junto com a função getch (ou getch no Windows).
esta função getkey é específica para o sistema operacional Windows.

Sign in to comment.

More Answers (1)

MathWorks MATLAB Hardware Team
Thank you for contacting us.
To enhance your experience interfacing Arduino with MATLAB, we suggest utilizing the MATLAB Support Package for Arduino hardware. You can find more information here:
Best regards,
MATLAB Hardware Team


Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!