Advertisement
TLama

Untitled

Nov 5th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.35 KB | None | 0 0
  1. type
  2.   TForm1 = class(TForm)
  3.     ApplicationEvents1: TApplicationEvents;
  4.     procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
  5.   private
  6.     FLastCtrl: HWND;
  7.     FLastTick: DWORD;
  8.     FClickCnt: Integer;
  9.   end;
  10.  
  11. implementation
  12.  
  13. procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
  14. begin
  15.   if Msg.message = WM_LBUTTONDOWN then
  16.   begin
  17.     // if the same control as before was "left mouse button down-ed", then...
  18.     if (Msg.hwnd = FLastCtrl) then
  19.     begin
  20.       // if 1 second elapsed (1000 here is 1000 ms), then...
  21.       if (GetTickCount - FLastTick >= 1000) then
  22.       begin
  23.         // if the user "left mouse button down-ed" at least 3 times the same control in one second, then...
  24.         if FClickCnt >= 3 then
  25.           // somone clicked the same control at least 3 times per second
  26.         // count this click (it is after that elapsed 1 second period)
  27.         FClickCnt := 1;
  28.         // and store this tick
  29.         FLastTick := GetTickCount;
  30.       end
  31.       // the period of 1 second did not yet elapsed, so let's just increase the click counter
  32.       else
  33.         Inc(FClickCnt);
  34.     end
  35.     else
  36.     begin
  37.       // count this click, store this control handle and this tick
  38.       FClickCnt := 1;
  39.       FLastCtrl := Msg.hwnd;
  40.       FLastTick := GetTickCount;
  41.     end;
  42.   end;
  43. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement