Прерывание клавиши Tab
Единственное место в программе, где можно перехватить нажатие клавиши tab - в обработчике Application.OnMessages. Пример ниже:
unit Hndltabu;
interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; procedure FormCreate(Sender: TObject); private { Private-Deklarationen } procedure AppMessage(var Msg: TMsg; var Handled: Boolean); public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean); const shiftPressed: boolean = false; begin if Msg.Message = WM_KEYDOWN then if not shiftPressed and (Msg.wParam = VK_SHIFT) then begin shiftPressed := true; Exit; end else begin if Msg.wParam = VK_TAB then if ActiveControl = Edit1 then begin if shiftPressed then Label1.Caption := 'BACKTAB!' else Label1.Caption := 'TAB!'; Handled := true end else Label1.Caption := ''; shiftPressed := false; end; end; procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := AppMessage; end; end. |
- Ralph Friedman [000956]