[cc,cmdarray]=readkeyboardchar(cmdarray)
cmdarray : | optional keyboard buffer to extend OR false for delete keyboard buffer |
cc : | last char or empty | |
cmdarray : | keyboard including last char |
[a,b]=readkeyboardchar(false); while ~isequal(a,char(13)); [a,b]=readkeyboardchar(b);end; b, uint8(b)
This function, readkeyboardchar
, is designed for serial robotics terminal communication. It reads a single keyboard key without waiting for input, unlike getkeyboardchar
. The function also has the side effect of plotting the key in the command window.
false
to delete the keyboard buffer.shg
and pause for a brief moment (0.001 seconds).cmdarray
is provided and is a logical value:
char(0)
and clear cmdarray
.cmdarray
is not provided, initialize it as an empty array.get(gcf,'CurrentCharacter')
and convert it to an unsigned 8-bit integer (uint8
).char(0)
.cc
is not empty):
char(8)
) to the command window.cmdarray
.The following example demonstrates how to use the function to read characters until the Enter key (character 13) is pressed:
[a,b]=readkeyboardchar(false); while ~isequal(a,char(13)); [a,b]=readkeyboardchar(b); end; b, uint8(b)Algorithm explaination created using ChatGPT on 2025-08-19 01:20. (Please note: No guarantee for the correctness of this explanation)