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

  1. unit Keyev;
  2. interface
  3.  
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   StdCtrls;
  7.  
  8. type
  9.   TForm1 = class(TForm)
  10.     Edit1: TEdit;
  11.     Memo1: TMemo;
  12.     Button1: TButton;
  13.     procedure Edit1KeyDown(Sender: TObject; var Key: Word;
  14.       Shift: TShiftState);
  15.     procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  16.     procedure Edit1KeyUp(Sender: TObject; var Key: Word;
  17.       Shift: TShiftState);
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  34.   Shift: TShiftState);
  35. var
  36.    s : string;
  37. begin
  38.   s := '';
  39.   if ssCtrl in Shift then s := s + 'CTRL-';
  40.   if ssAlt in Shift then s := s + 'ALT-';
  41.   if ssShift in Shift then s := s + 'SHIFT-';
  42.   Memo1.Lines.Add( Format('Edit1KeyDown: Key Code: %d, Key = %s%s', [Key,s,Chr(Key)] ));
  43.   if Key = vk_Multiply then
  44.      Caption := 'The Multiply Key!'
  45.   else
  46.      Caption := Chr(Key);
  47. end;
  48.  
  49. procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
  50. begin
  51.   Memo1.Lines.Add( Format('Edit1KeyPress: Key = %s', [Key] ));
  52. end;
  53.  
  54. procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  55.   Shift: TShiftState);
  56. var
  57.    s : string;
  58. begin
  59.   s := '';
  60.   if ssCtrl in Shift then s := s + 'CTRL-';
  61.   if ssAlt in Shift then s := s + 'ALT-';
  62.   if ssShift in Shift then s := s + 'SHIFT-';
  63.   Memo1.Lines.Add( Format('Edit1KeyUp: Key Code: %d, Key = %s%s', [Key,s,Chr(Key)] ));
  64.   Memo1.Lines.Add( '----------------' );
  65. end;
  66.  
  67. procedure TForm1.Button1Click(Sender: TObject);
  68. begin
  69.  Memo1.Clear;
  70.  Edit1.SetFocus;
  71. end;
  72.  
  73. end.
  74.