Writing a Keyloop Function

Keyloop functions that you write must conform to the following call:

int keyloop_func(counter)

int counter;            /* Counter value passed by ki()        */

ki() supplies the argument values. The first time that the keyloop function is called, ki() passes a KL_INIT to the keyloop function. The next, and subsequent times, the keyloop function is called, a KL_WAIT is passed. When ki() finds a key available or when the keyloop function returns a non-zero value, the keyloop function is called a last time, this time passing a KL_DONE. This allows the keyloop functions to perform initialization on the first pass (when it is passed a KL_INIT) and clean-up tasks on the last pass (when the function is passed a KL_DONE).

Return 0 if you want to continue waiting for a keystroke. As long as the keyloop function returns 0 and no keycode is found in the keyboard buffer, ki() continues to call the keyloop function.

Return a non-zero value if you want ki() to return. If your keyloop function returns a non-zero value, ki() treats this value as a valid keycode to be returned by ki(). The value will be passed to the key filter function (if one is installed).

The keyloop function is guaranteed to be called twice if it is installed, once with a value of KL_INIT and once with a value of KL_DONE. Initialization tasks should be performed when a KL_INIT is passed to the keyloop function. Clean-up tasks should be performed when a value of KL_DONE is passed.

Cautions: If you return a non-zero value in the last call to the keyloop function (when it is passed a KL_DONE as an argument), this value will be returned by ki().

Do not call ki() from a keyloop function.


Home Contents Previous Next