SGkeyboardCallback

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - User interface
Introduced first in SolidGeometry 4.5, Creation date: 2019-02-07, Last change: 2025-09-14

used as KeyPressFcn-Callback within SG-Library

Description

This function helps to have easier access to pressed keyboard keys. It is automatically installed by the function "SGkeyboardgetkey". It requires an open figure window.

See Also: SGkeyboardgetkey , RRRun

Example Illustration

 missing image of SGkeyboardCallback(src,event)

Syntax

SGkeyboardCallback(src,event)

Input Parameter

src: src of callback events
event: result of callback events

Examples


SGfigure; rotate3d off; set(gcf,'KeyPressFcn',@SGkeyboardCallback);
SGfigure; for i=1:100; a=SGkeyboardgetkey; if~isempty(a); cla; textVL([.5 .5],'',24,'',a.key); end; pause(.1); end;commandwindow;




Copyright 2019-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, SGkeyboardCallback, is designed to handle keyboard events within the SG-Library, specifically for capturing key presses in a MATLAB figure window. It is typically used as a callback function for the KeyPressFcn property of a figure.

Input Parameters

Algorithm Steps

  1. Declare a global variable SGlastkey to store information about the last key press event.
  2. Extract the modifier keys from the event structure and convert them to a string using cell2mat.
  3. Store the source of the event in SGlastkey.src.
  4. Check if SGlastkey has a field cnt. If not, initialize it to 0; otherwise, increment it by 1. This field likely counts the number of key press events.
  5. Store the character representation of the key in SGlastkey.chr.
  6. Store the key name in SGlastkey.key.
  7. Store the modifier keys in SGlastkey.mod.
  8. Record the current time using tic and store it in SGlastkey.tic.
  9. Convert the character to its uint8 representation and store it in SGlastkey.uint8.
  10. There is a commented-out section that would stop execution if the key "command" and "dot" are pressed together, indicating a potential debugging or error-handling feature.
Algorithm explaination created using ChatGPT on 2025-08-19 08:09. (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