unit MainFormUnit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, Math; type { TMainForm } TMainForm = class(TForm) Shape: TShape; procedure ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); private { private declarations } public { public declarations } end; var MainForm: TMainForm; implementation {$R *.lfm} const SYNC = 16; MOUSE_SEQUENCE : array[0..SYNC] of Word = ( $0492, $0960, $0618, $014A, $0A41, $0249, $0096, $0861, $041A, $0168, $0690, $0942, $0A14, $0294, $0069, $0816, $04A1); function SequenceToNybble(const s : Word) : Byte; begin for Result := 0 to SYNC do if s = MOUSE_SEQUENCE[Result] then Exit; Result := 255; end; { TMainForm } procedure TMainForm.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); const lastX : Integer = 0; lastY : Integer = 0; Sequence : QWord = 0; // 64-Bit var dx, dy : Byte; Nybble : Byte; b : Byte; begin dx := min(X - lastX + 1, 3); dy := min(Y - lastY + 1, 3); Sequence := (Sequence SHL 4) + (dx SHL 2) + dy; if (Sequence SHR 24) AND ($FFF) = MOUSE_SEQUENCE[SYNC] then begin Nybble := SequenceToNybble((Sequence SHR 12) AND ($FFF)); if Nybble < SYNC then begin b := Nybble SHL 4; Nybble := SequenceToNybble(Sequence AND ($FFF)); if Nybble < SYNC then begin Inc(b, Nybble); Shape.Brush.Color := RGBToColor(b, b, b); Sequence := 0; end; end; end; lastX := X; lastY := Y; end; end.