Function:cs2skcb

From S2PLOT

Jump to: navigation, search

cs2skcb

Set the keyboard callback.

Prototype

void cs2skcb(void *cbfn);

Description

Set the user-installed keyboard callback function. Use NULL arg to disable the keyboard callback. When registered, this function gets to process normal keyboard (ascii) presses before S2PLOT's internal handling. It can consume the event (by returning 1) and prevent the default S2PLOT handling. A return value of 0 should be used when the key was not processed. The callback function should have the form:

int kbdcallback(unsigned char *key)

Shift-ESC cannot be over-ridden.


See Also

cs2scbSet the callback function.

Code Example

include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "s2plot.h"

/* Global variables */
char keyval;                            /* Key that was pressed */
int keyp = 0;                           /* Flag indicating valid key */

int kcb(unsigned char *key)
{
   keyp = 0;                            /* Default value */
   switch (toupper(key[0])) {           /* What was pressed ? */
      case 'A' : keyval = 'a';          /* Set the value of key pressed */
                 keyp = 1;              /* Set the flag */
                 return 1;              /* Do not process "autospin" command */
                 break;
      case 'D' : keyval = 'd';          /* Set the value of key pressed */
                 keyp = 1;              /* Set the flag */
                 return 0;              /* Process "debug" as normal */
                 break;
   }
   return 0;                            /* Process all other keys normally */
}

void cb(double *t, int *kc)
{
   char string[32];
   if (keyp) {                          /* Was a valid key pressed ?*/
      sprintf(string,"You pressed: %c",keyval);
   } else {
      sprintf(string,"Press <a> or <d>");
   }
   s2textxy(-1,0,0,string);             /* Write the text to screen */
}

int main(int argc, char *argv[])
{
   s2opend("/s2mono", argc, argv);              /* Open in mono mode */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   cs2scb(cb);                                  /* Install dynamic callback */
   cs2skcb(kcb);                                /* Install keyboard callback */

   s2show(1);                                   /* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.


Personal tools