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
- src: The source of the callback event, usually the figure window where the key press occurred.
- event: A structure containing information about the key press event, including the key pressed, any modifiers (like Ctrl or Shift), and the character representation of the key.
Algorithm Steps
- Declare a global variable
SGlastkey
to store information about the last key press event.
- Extract the modifier keys from the
event
structure and convert them to a string using cell2mat
.
- Store the source of the event in
SGlastkey.src
.
- 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.
- Store the character representation of the key in
SGlastkey.chr
.
- Store the key name in
SGlastkey.key
.
- Store the modifier keys in
SGlastkey.mod
.
- Record the current time using
tic
and store it in SGlastkey.tic
.
- Convert the character to its
uint8
representation and store it in SGlastkey.uint8
.
- 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