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

 missing image of readkeyboardchar(cmdarray)

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

Output Results

Algorithm Steps

  1. Display the current figure window using shg and pause for a brief moment (0.001 seconds).
  2. 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.
  3. If cmdarray is not provided, initialize it as an empty array.
  4. Retrieve the current character from the figure window using get(gcf,'CurrentCharacter') and convert it to an unsigned 8-bit integer (uint8).
  5. Reset the current character of the figure to char(0).
  6. 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