home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / PART231.ZIP / SOURCES.ZIP / KEYCODES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  3.3 KB  |  123 lines

  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. #include "conio.h"
  5.  
  6. void key_codes(void);
  7.  
  8. void main(void)
  9. {
  10.  struct event ev;
  11.  
  12.  conio_init();
  13.  cursor_size(16,14);
  14.  show_mouse();
  15.  
  16.  write_string(  Green, 10, ScreenHeight, "Use arrows to move window.  Press ESC twice to exit." );
  17.  
  18.  key_codes();
  19.  
  20.  hide_mouse();
  21.  cursor_size(14,16);
  22. }/* main */
  23.  
  24.  
  25.  
  26. void key_codes(void)
  27. {
  28.  char *WindowBuff, *event, temp1[40], temp2[40];
  29.  int last_key=0;
  30.  int flag=1;
  31.  static int x=20, y=6, w=25, h=9,  px, py;
  32.  int Attr1=Yellow+BakRed;
  33.  int Attr2=BrCyan+BakRed;
  34.  struct event ev;
  35.  
  36.  if( (WindowBuff=(char*)malloc(w*h*2))==0 ) return;
  37.  
  38.  get_event(&ev,EV_NONBLOCK);
  39.  
  40.  while(1)
  41.     {
  42.      if( flag==1 )
  43.        {
  44.         px=x;
  45.         py=y;
  46.         save_window( x,y,w,h, WindowBuff );
  47.         clear_window(  Attr1, x,y,w,h );
  48.         border_window(  Attr1, x,y,w,h, Border22f );
  49.         flag=0;
  50.        }
  51.  
  52.      event="NONE";
  53.      if( ev.ev_type & EV_TIMER ) event="(EV_TIMER)";
  54.      if( ev.ev_type & EV_MOUSE ) event="(EV_MOUSE)";
  55.      if( ev.ev_type & EV_SHIFT ) event="(EV_SHIFT)";
  56.      if( ev.ev_type & EV_KEY ) { event="(EV_KEY)  ";
  57.  
  58.         if( ev.key!=0 )  sprintf(temp1,"Ascii code: 0x%02X ('%c')",ev.key,ev.key);
  59.                  else    sprintf(temp1,"Ascii code: 0x%02X      ",ev.key);
  60.                          sprintf(temp2,"Scan  code: 0x%04X    ",ev.scan);
  61.        }
  62.      else
  63.        {
  64.         sprintf(temp1,"Ascii code: undefined ");
  65.         sprintf(temp2,"Scan  code: undefined ");
  66.        }
  67.  
  68.      write_string(Attr2,x+2,y+2,temp1);
  69.      write_string(Attr2,x+2,y+3,temp2);
  70.  
  71.      sprintf(temp1,"Event: %2d %10s", ev.ev_type,event);
  72.      write_string(Attr2,x+2,y+1,temp1);
  73.      
  74.      sprintf(temp1,"Shifts status:   %04X",ev.shift); write_string(Attr2,x+2,y+4,temp1);
  75.      sprintf(temp1,"Shifts changed:  %04X",ev.shiftX); write_string(Attr2,x+2,y+5,temp1);
  76.  
  77.   if( MouseInstalled )
  78.     {
  79.      sprintf(temp1,"Mouse X: %2d",ev.x); write_string(Attr2,x+2,y+6,temp1);
  80.      sprintf(temp1,"Mouse Y: %2d",ev.y); write_string(Attr2,x+2,y+7,temp1);
  81.      sprintf(temp1,"Left : %d",ev.left); write_string(Attr2,x+15,y+6,temp1);
  82.      sprintf(temp1,"Right: %d",ev.right); write_string(Attr2,x+15,y+7,temp1);
  83.     }
  84.   else
  85.     {
  86.      write_string(Attr2,x+2,y+7,"Mouse is not detected");
  87.     }
  88.  
  89.      ev.timer=0x100;
  90.      
  91.      get_event( &ev, EV_KEY | EV_SHIFT | EV_MOUSE | EV_TIMER );
  92.  
  93.      if( ev.ev_type & EV_KEY )
  94.        {
  95.         if( ev.key==0x1B && last_key==0x1B ) break;
  96.  
  97.         last_key=ev.key;
  98.  
  99.         switch(ev.scan&0xFF00)
  100.             {
  101.              case 0x4800: if( y>1 ) y--;           /* UP */
  102.                                   break;
  103.              case 0x4B00: if( x>1 ) x--;           /* LEFT */
  104.                                   break;
  105.              case 0x4D00: if( x+w-1 < ScreenWidth ) x++;    /* RIGHT */
  106.                                   break;
  107.              case 0x5000: if( y+h-1 < ScreenHeight ) y++;    /* DOWN */
  108.                                    break;
  109.              default    : break;
  110.             }
  111.        }/* EV_KEY */
  112.        
  113.      if( x!=px || y!=py )
  114.        {
  115.         load_window( px,py,w,h, WindowBuff );
  116.         flag=1;
  117.        }
  118.     }/* while(1) */
  119.  
  120.  load_window( x,y,w,h, WindowBuff );
  121.  free(WindowBuff);
  122. }/* key_codes */
  123.