Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Key State Macro
Since it is a read-only macro it can only appear on the right side of an expression. The format is Key?n, where n is a single symbol or character.
Note that Daqarta dialog hot-keys are not disabled just because they are used for macro control. For example, if the Generator control dialog is open and has the keyboard focus (highlighted from having clicked the mouse on it), then the unshifted 'g' key will toggle the Generator on or off. It will do this even if your macro is using that key for another purpose. The best way to avoid unintended operations is to not open main Daqarta control dialogs when you are running macros that use keyboard control.
However, the Key? macros ignore keystrokes used for text or value entry.
Key?! returns the value of a key that is down at the time the command that uses this is executed. For example A=Key?! sets Macro Variable A to the key value, if any. If no key is down, A is set to 0.
Key?# returns the value of the most recent key to go down, even if it has been released by the time the command is executed. The internal value is automatically cleared after reading. If the key is held down while being read repeatedly, the return will alternate between the key value and zero.
Only keys for "printable" alphanumeric or symbol characters (including spaces) can be read by these methods, not shift keys, Tab, Enter, Backspace, function keys, etc. The values are case sensitive, such that 'A' returns 0x41 (65), while 'a' returns 0x61 (97). Similarly, '1' returns 0x31 (49), while the shifted version '!' returns 0x21 (33).
The lowest number that can be returned is 32 (space) and the highest is 126 (tilde ~).
If you want to use the keyboard to set some variable V over a given range R, you can use V=R/(126-32) * (Key?# - 32). When Key?# returns 32, the second term is zero so the product is zero. When Key?# returns 126, the product is simply R.
When there is no key pressed Key?# returns 0, which yields a negative value from the above expression. To avoid setting the variable with that you can use an IF statement and an intermediate variable I:
I=Key?# IF.I!=0 V=R/(126-32) * (I - 32) ENDIF.
The intermediate variable I is needed so Key?# is only read once, since reading the key value also clears it to the current state, which may very well be 0 if the key has already been released.
Key?$ returns the current (not recent) shift states. The CTRL, ALT, and SHIFT keys are encoded into the bits of the return value such that:
1 = CTRL 2 = ALT 4 = SHIFT
If multiple shift keys are down, the returned value will be the sum of the relevant bit values. For example, 3 means that both CTRL and ALT are currently down.
The format is Key?a, where a is an alphanumeric character (case ignored). For example, A=Key?q will set Macro Variable A to 1 if the 'q' key is down at the time the command is processed, or else 0 if it is up.
Since Key?a only returns values of 0 or 1, it seems natural to use this to control a toggle-type Daqarta variable such as Burst On/Off with something like L.0.Burst=Key?b. But note that this would cause the Burst state to be on only when the 'b' key was held down, since if this macro runs when the key is up the return value is 0.
You could use 'B' to set Burst on, and 'b' to turn it off, by testing for the SHIFT state:
IF.Key?b=1 IF.Key?$=>3 L.0.Burst=1 ELSE. L.0.Burst=0 ENDIF. ENDIF.
Note that this same thing could be done with Key?# using:
K=Key?# IF.K="B" L.0.Burst=1 ENDIF. IF.K="b" L.0.Burst=0 ENDIF.
See also Macro Overview
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2017 by Interstellar Research
All rights reserved