home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_PAS / KEYCTRL.ZIP / KEYCTRL.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-07  |  4KB  |  171 lines

  1. Unit KeyCtrl;
  2. {$F+,O+,A-}
  3.  
  4. {Written By Paul Backus 1994,
  5.  Schippersdreef 44c
  6.  6216 TL Maastricht
  7.  Telf. 31,043-433872
  8.  CopyRights (c) 1994
  9.  Compuserve 73064,2473
  10.  
  11.  The sources may be used as is on your own risk.
  12.  
  13.  KeyCtrl is a Simple Demo of how to jump from field to field
  14.  by using the cursor keys instead of the tab key. It also works
  15.  for the Pushbuttons. Its also gives you an example of how to control
  16.  a pushbutton by modifying the state of the radiobutton.
  17.  
  18.  Please Let me Know
  19.  - if you find other possibilities.
  20.  - what you think of the keyCtrl.
  21.  
  22.  GoodLuck.
  23. }
  24.  
  25. interface
  26. Uses  App, Dialogs, Drivers, Objects, Views, MsgBox;
  27.  
  28. Type
  29.  
  30.   PMyInputLine=^TmyInputLine;
  31.   TMyInputLine=Object (TInputLine)
  32.     Procedure handleevent(var event:Tevent);  Virtual;
  33.   end;
  34.  
  35.   PMyButton=^TMyButton;
  36.   TMyButton=object (TButton)
  37.     procedure handleevent(var event:Tevent);  Virtual;
  38.   end;
  39.  
  40.  
  41.   PHorizontalButtons=^THorizontalButtons;
  42.   THorizontalButtons=Object(TRadioButtons)
  43.     PtrButton : PMyButton;
  44.     procedure handleevent(var event:Tevent); Virtual;
  45.   end;
  46.  
  47.  
  48.   PVerticalButtons=^TVerticalButtons;
  49.   TVerticalButtons=Object(TRadioButtons)
  50.     PtrButton : PMyButton;
  51.     procedure handleevent(var event:Tevent); Virtual;
  52.   end;
  53.  
  54.  
  55. implementation
  56.  
  57. {TMyInputLine}
  58.  
  59. Procedure TMyInputLine.handleevent(var Event:Tevent);
  60.  
  61. begin
  62.   if event.what=evnothing then exit;
  63.   inherited handleevent(event);
  64.   if state and sffocused<>0 then
  65.     if event.what=evkeydown then
  66.       case event.keycode of
  67.         kbdown :
  68.           begin
  69.             owner^.selectnext(false);
  70.             clearevent(event);
  71.           end;
  72.         kbup  :
  73.           begin
  74.             owner^.selectnext(true);
  75.             clearevent(event);
  76.           end;
  77.      end;
  78. end;
  79.  
  80. {TMybutton PB!!}
  81.  
  82. procedure TMyButton.HandleEvent(var Event: TEvent);
  83.  
  84. begin
  85.   inherited handleevent(event);
  86.   if event.what=evkeydown then
  87.     if state and sffocused <>0 then
  88.         case event.keycode of  {PB!!}
  89.           kbdown  ,
  90.           kbright :
  91.             begin
  92.               owner^.focusnext(false);
  93.               clearevent(event);
  94.             end;
  95.           kbup   ,
  96.           kbleft :
  97.             begin
  98.               owner^.focusnext(true);
  99.               clearevent(event);
  100.             end;
  101.         end;
  102. end;
  103.  
  104.  
  105. {THorizontalButton  PB!!}
  106.  
  107. Procedure THorizontalButtons.HandleEvent(Var Event:Tevent);
  108. var SaveValue:Word;
  109. begin
  110.   SaveValue:=Value;
  111.   if state and sffocused<>0 then
  112.     if event.what=evkeydown then
  113.       case event.keycode of
  114.         kbdown :
  115.           begin
  116.             owner^.selectnext(false);
  117.             clearevent(event);
  118.           end;
  119.         kbup  :
  120.           begin
  121.             owner^.selectnext(true);
  122.             clearevent(event);
  123.           end;
  124.      end;
  125.  
  126.   inherited handleevent(event);
  127.   if state and sffocused<>0 then
  128.      begin
  129.        if PtrButton<>nil then
  130.          if saveValue<>Value then
  131.            begin
  132.              if value = 1 then disablecommands([ptrbutton^.command]);
  133.              if value = 0 then enablecommands([ptrbutton^.command]);
  134.            end;
  135.      end;
  136. end;
  137.  
  138. {TVerticalButton  PB!!}
  139.  
  140. Procedure TVerticalButtons.HandleEvent(Var Event:Tevent);
  141. var SaveValue:Word;
  142. begin
  143.   SaveValue:=Value;
  144.   if state and sffocused<>0 then
  145.     if event.what=evkeydown then
  146.       case event.keycode of
  147.         kbleft :
  148.           begin
  149.             owner^.selectnext(true);
  150.             clearevent(event);
  151.           end;
  152.         kbright  :
  153.           begin
  154.             owner^.selectnext(false);
  155.             clearevent(event);
  156.           end;
  157.      end;
  158.  
  159.   inherited handleevent(event);
  160.   if state and sffocused<>0 then
  161.      begin
  162.        if PtrButton<>nil then
  163.          if saveValue<>Value then
  164.            begin
  165.              if value = 1 then disablecommands([ptrbutton^.command]);
  166.              if value = 0 then enablecommands([ptrbutton^.command]);
  167.            end;
  168.      end;
  169. end;
  170.  
  171. end.