readkeyboardchar
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - User interface
Introduced first in SolidGeometry 5.4, Creation date: 2024-03-02, Last change: 2025-09-15
reads a single keyboard key or returns empty
Description
THIS function readkeyboardchar is used for the serial robotics terminal communication.
In contrast to getkeyboardchar, this function does not wait.
A problem is, that the key is plotted in the command window.
See Also: getkeyboardchar
Example Illustration
Syntax
[cc,cmdarray]=readkeyboardchar(cmdarray)
Input Parameter
cmdarray: | | optional keyboard buffer to extend OR false for delete keyboard buffer |
Output Parameter
cc: | | last char or empty |
cmdarray: | | keyboard including last char |
Examples
[a,b]=readkeyboardchar(false); while ~isequal(a,char(13)); [a,b]=readkeyboardchar(b);end; b, uint8(b)
Copyright 2024-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
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.
Input Parameters
- cmdarray: An optional parameter that serves as a keyboard buffer. It can be extended with new input or set to
false to delete the keyboard buffer.
Output Results
- cc: The last character read from the keyboard or empty if no character is read.
- cmdarray: The updated keyboard buffer, including the last character read.
Algorithm Steps
- Display the current figure window using
shg and pause for a brief moment (0.001 seconds).
- Check if
cmdarray is provided and is a logical value:
- If true, set the current character of the figure to
char(0) and clear cmdarray.
- If
cmdarray is not provided, initialize it as an empty array.
- Retrieve the current character from the figure window using
get(gcf,'CurrentCharacter') and convert it to an unsigned 8-bit integer (uint8).
- Reset the current character of the figure to
char(0).
- If a character is read (i.e.,
cc is not empty):
- Print a backspace character (
char(8)) to the command window.
- Append the character to
cmdarray.
Example Usage
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)
Last html export of this page out of FM database by TL: 2025-09-21