home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / KB_V02.ZIP / TEST_KB.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1989-10-18  |  2.4 KB  |  112 lines

  1. program test_KB;
  2.  
  3.    { Demonstates the use of the KB_v02 Unit. }
  4.  
  5.    uses crt, KB_v02;
  6.  
  7.    const on       = 'Key is Pressed   ';
  8.          off      = 'Key isn''t Pressed';
  9.          EveryMsg = 'Any Key to Force ';
  10.          MidMsg   = ' Lock Key to ';
  11.  
  12.          lock_keys   :  array[1..3] of byte =
  13.  
  14.                         ( Number_Lock_Key, Caps_Lock_Key, Scroll_Lock_Key );
  15.  
  16.          key_states  :  array[1..3] of byte =
  17.  
  18.                        ( State_On, State_Off, State_Toggle );
  19.  
  20.  
  21.          key_names    :  array[1..3] of string = ('Number','Caps','Scroll');
  22.          state_names  :  array[1..3] of string = ('On','Off','Toggle');
  23.  
  24.  
  25.  
  26.    var i,j  :  byte;
  27.  
  28.    procedure BurnKey;
  29.  
  30.       var ch  :  char;
  31.  
  32.       begin
  33.  
  34.          ch := readkey;
  35.          if ch = #0 then ch := readkey;
  36.  
  37.       end;
  38.  
  39.    procedure writeAT( x,y  :  byte;  st  :  string );
  40.  
  41.       begin
  42.  
  43.          gotoxy( x,y );
  44.          write( st );
  45.  
  46.       end;
  47.  
  48.  
  49.    begin
  50.  
  51.       clrscr;
  52.       writeln( 'DEMO of Is_Keypressed Function' );
  53.       writeln;
  54.       writeln( ' Any Normal Key to continue ' );
  55.  
  56.       writeAT( 10, 10, 'Alt Key Status'  );
  57.       writeAT( 10, 12, 'CTRL Key Status' );
  58.       writeAT( 10, 14, 'Left Shift Status' );
  59.       writeAT( 10, 16, 'Right Shift Status' );
  60.  
  61.  
  62.       repeat
  63.  
  64.           if Is_Key_Pressed( Alt_Key ) then writeAT( 30,10, on )
  65.           else writeAT( 30,10, off );
  66.  
  67.           if Is_Key_Pressed( Control_Key ) then writeAT( 30,12, on )
  68.           else writeAT( 30,12, off );
  69.  
  70.           if Is_Key_Pressed( Left_Shift ) then writeAT( 30,14, on )
  71.           else writeAT( 30,14, off );
  72.  
  73.           if Is_Key_Pressed( Right_Shift ) then writeAT( 30,16, on )
  74.           else writeAT( 30,16, off );
  75.  
  76.           delay(100);
  77.  
  78.       until keypressed;
  79.  
  80.       clrscr;
  81.  
  82.       burnkey;
  83.       writeln('Keyboard Status Saved' );
  84.       writeln;
  85.  
  86.       Save_Keyboard_Status;
  87.  
  88.       for i := 1 to 3 do begin
  89.  
  90.           for j := 1 to 3 do begin
  91.  
  92.               writeln( EveryMsg, key_names[i], MidMsg, state_names[j] );
  93.               burnkey;
  94.               Set_Keyboard_State( Lock_Keys[i], key_States[j] );
  95.  
  96.           end;
  97.  
  98.           writeln;
  99.  
  100.       end;
  101.  
  102.       writeln;
  103.       writeln( 'End of Demo.' );
  104.       writeln( 'Any Key to Restore Original Lock Status and Exit.' );
  105.  
  106.       BurnKey;
  107.  
  108.       Restore_Keyboard_Status;
  109.  
  110.    end.
  111.  
  112.