home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue154 / delphi / shiftstates / SHIFT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-04-26  |  2.2 KB  |  103 lines

  1. unit shift;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ComCtrls, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     SBar: TStatusBar;
  12.     RichEdit1: TRichEdit;
  13.     procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
  14.       Shift: TShiftState);
  15.     procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;
  16.       Shift: TShiftState);
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.     procedure ShowShiftStates;
  23.     procedure ShowToggleStates;
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TForm1.ShowShiftStates;
  34. begin
  35.   if (GetKeyState( vk_Control ) < 0) then
  36.      SBar.Panels[0].Text := 'CTRL DOWN'
  37.   else
  38.       SBar.Panels[0].Text := 'CTRL UP';
  39.   if (GetKeyState( vk_Menu ) < 0) then   { vk_Menu is the constant for Alt! }
  40.      SBar.Panels[1].Text := 'ALT DOWN'
  41.   else
  42.       SBar.Panels[1].Text := 'ALT UP';
  43.   if (GetKeyState( vk_Shift ) < 0) then
  44.      SBar.Panels[2].Text := 'SHIFT DOWN'
  45.   else
  46.       SBar.Panels[2].Text := 'SHIFT UP';
  47. end;
  48.  
  49. procedure TForm1.ShowToggleStates;
  50. var
  51.    s : string;
  52. begin
  53.    s := 'Numlock';
  54.    if (GetKeyState( vk_NumLock ) < 0) then
  55.        s := s + '[DOWN]'
  56.    else
  57.        s := s + '[ UP ]';
  58.    if Bool(GetKeyState( vk_NumLock ) and 1) then
  59.       s := s + ' ON  '
  60.    else
  61.       s := s + ' OFF ';
  62.    s := s + 'Capslock';
  63.    if (GetKeyState( vk_Capital ) < 0) then
  64.        s := s + '[DOWN]'
  65.    else
  66.        s := s + '[ UP ]';
  67.    if Bool(GetKeyState( vk_Capital ) and 1) then
  68.       s := s + ' ON  '
  69.    else
  70.       s := s + ' OFF ';
  71.    if Bool(GetKeyState( vk_Insert ) and 1) then
  72.       s := s + ' INSERT  '
  73.    else
  74.       s := s + ' OVERTYPE ';
  75.  
  76.    SBar.Panels[3].Text := s;
  77.  
  78. end;
  79.  
  80.  
  81. procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  82.   Shift: TShiftState);
  83. begin
  84.      if Key = vk_F2 then Close;
  85.      ShowShiftStates;
  86.      ShowToggleStates;
  87. end;
  88.  
  89. procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word;
  90.   Shift: TShiftState);
  91. begin
  92.      ShowShiftStates;
  93.      ShowToggleStates;
  94. end;
  95.  
  96. procedure TForm1.FormCreate(Sender: TObject);
  97. begin
  98.      ShowShiftStates;
  99.      ShowToggleStates;
  100. end;
  101.  
  102. end.
  103.