⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mousekey.pas

📁 《Kylix程序设计》一书中附带的例程源代码
💻 PAS
字号:
unit MouseKey;interfaceuses  Qt, SysUtils, Types, Classes, Variants, QGraphics, QControls, QForms, QDialogs,  QStdCtrls, QExtCtrls;type  TFrmMain = class(TForm)    procedure FormClick(Sender: TObject);    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure FormKeyDown(Sender: TObject; var Key: Word;      Shift: TShiftState);    procedure FormKeyPress(Sender: TObject; var Key: Char);    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,      Y: Integer);    procedure FormKeyUp(Sender: TObject; var Key: Word;      Shift: TShiftState);  private    { Private declarations }  public    { Public declarations }  end;var  FrmMain: TFrmMain;implementation{$R *.xfm}procedure TFrmMain.FormClick(Sender: TObject);begin{  QDialogs.MessageDlg( 'Information', 'Hello, Kylix-fans.',    mtInformation, [ mbOk ], 0, mbOk, nil );}end;procedure TFrmMain.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var  OutMsg: string;begin//  if ssRight in Shift then  // if Mouse right button clicked{  if Button = mbLeft then// This is not needed.//  if HitTest( X, Y ) then//  if ( X >= 0 ) and ( X < ClientWidth ) and ( Y >= 0 ) and ( Y < ClientHeight ) then  begin    OutMsg := 'Hello, Kylix-fans. Mouse Left Button clicked at ( ' + IntToStr( X ) + ', ' + IntToStr( Y ) + ' ).';    Application.MessageBox( OutMsg, 'Information', [ smbOK ], smsInformation );// This puts you into the trouble of many clicks.//    QDialogs.MessageDlg( 'Information', OutMsg, mtInformation, [ mbOk ], 0, mbOk, nil );  end;}  case Button of    mbLeft:    begin// This is not needed.//      if HitTest( X, Y ) then//      if ( X >= 0 ) and ( X < ClientWidth ) and ( Y >= 0 ) and ( Y < ClientHeight ) then//      begin        OutMsg := 'Hello, Kylix-fans. Mouse Left Button clicked at ( ' + IntToStr( X ) + ', ' + IntToStr( Y ) + ' ).';        Application.MessageBox( OutMsg, 'Information', [ smbOK ], smsInformation );// This puts you into the trouble of many clicks.//        QDialogs.MessageDlg( 'Information', OutMsg, mtInformation, [ mbOk ], 0, mbOk, nil );//      end;    end;    mbRight:    begin      Canvas.Brush.Style := bsClear;      OutMsg := 'Mouse Right Button clicked at ( ' + IntToStr( X ) + ', ' + IntToStr( Y ) + ' ).';      Canvas.TextOut( X, Y, OutMsg );    end;    mbMiddle:    begin    end;  end;{  if Button = mbRight then  // if Mouse right button clicked  begin    Canvas.Brush.Style := bsClear;    OutMsg := 'You Clicked at ( ' + IntToStr( X ) + ', ' + IntToStr( Y ) + ' ).';    Canvas.TextOut( X, Y, OutMsg );  end;}end;procedure TFrmMain.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);var  OutMsg: string;begin  OutMsg := 'You just pressed the key ' + Char( Key ) + '.';//  Application.MessageBox( OutMsg, 'Information', [ smbOK ], smsInformation );  Application.MessageBox( 'Down:' + OutMsg, 'Information', [ smbOK ], smsInformation );//  QDialogs.MessageDlg( 'Information', OutMsg, mtInformation, [ mbOk ], 0, mbOk, nil );end;procedure TFrmMain.FormKeyPress(Sender: TObject; var Key: Char);var  OutMsg: string;begin// After comments these, gets chap0315.bmp  OutMsg := 'You just pressed the key ' + Key + '.';//  OutMsg := 'You just pressed the key ' + Char(Ord(Key)) + '.';//  OutMsg := 'You just pressed the key ' + IntToStr(Ord(Key)) + '.';  Application.MessageBox( 'Press:' + OutMsg, 'Information', [ smbOK ], smsInformation );//  Application.MessageBox( OutMsg, 'Information', [ smbOK ], smsInformation );//  QDialogs.MessageDlg( 'Information', OutMsg, mtInformation, [ mbOk ], 0, mbOk, nil );end;procedure TFrmMain.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  Caption := 'Mouse moves to ( ' + IntToStr( X ) + ', ' + IntToStr( Y ) + ' ).';end;procedure TFrmMain.FormKeyUp(Sender: TObject; var Key: Word;  Shift: TShiftState);var  OutMsg: string;begin  OutMsg := 'You just pressed the key ' + Char( Key ) + '.';//  Application.MessageBox( OutMsg, 'Information', [ smbOK ], smsInformation );  Application.MessageBox( 'Up:' + OutMsg, 'Information', [ smbOK ], smsInformation );//  QDialogs.MessageDlg( 'Information', OutMsg, mtInformation, [ mbOk ], 0, mbOk, nil );end;end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -