Daqarta
Data AcQuisition And Real-Time Analysis
Scope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
The following is from the Daqarta Help system:

Features:

Oscilloscope

Spectrum Analyzer

8-Channel
Signal Generator

(Absolutely FREE!)

Spectrogram

Pitch Tracker

Pitch-to-MIDI

DaqMusiq Generator
(Free Music... Forever!)

Engine Simulator

LCR Meter

Remote Operation

DC Measurements

True RMS Voltmeter

Sound Level Meter

Frequency Counter
    Period
    Event
    Spectral Event

    Temperature
    Pressure
    MHz Frequencies

Data Logger

Waveform Averager

Histogram

Post-Stimulus Time
Histogram (PSTH)

THD Meter

IMD Meter

Precision Phase Meter

Pulse Meter

Macro System

Multi-Trace Arrays

Trigger Controls

Auto-Calibration

Spectral Peak Track

Spectrum Limit Testing

Direct-to-Disk Recording

Accessibility

Applications:

Frequency response

Distortion measurement

Speech and music

Microphone calibration

Loudspeaker test

Auditory phenomena

Musical instrument tuning

Animal sound

Evoked potentials

Rotating machinery

Automotive

Product test

Contact us about
your application!

Key State Macro


Macro: Key?

Introduction:

Key? is a read-only macro that can read the ASCII value of the key that is currently down or that has recently gone down, or read current shift states, or read the state (0 or 1) of a specific key.

The format is Key?n, where n is a single symbol or character. Since it is a read-only macro it can only appear on the right side of a normal expression such as UA=Key?a. It can appear on either side of an IF or WHILE expression, such as IF.Key?r=1 or WHILE.Key?r=0.

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.

Note that while it is possible use Key? in a loop that waits for a specified key, it is much more efficient to use WaitKey for that purpose.


Current or Recent ASCII Key Value:

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.


Shift States:

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.


Specific Key States:

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

GO:

Questions? Comments? Contact us!

We respond to ALL inquiries, typically within 24 hrs.
INTERSTELLAR RESEARCH:
Over 35 Years of Innovative Instrumentation
© Copyright 2007 - 2023 by Interstellar Research
All rights reserved