6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, Math, StrUtils;
10 TMouseGesture = class(TObject)
14 FGestureItemList: TStringList;
15 FBeginGesture: Boolean;
21 FOnGestureStart: TNotifyEvent;
22 FOnGestureMove: TNotifyEvent;
23 FOnGestureEnd: TNotifyEvent;
24 function GetGestureCount: Integer;
25 function CheckAction(Message: Integer; x, y: Integer): Boolean;
26 procedure AddAction(sx, sy: Integer);
27 function AddGesture(Item: string): Integer;
28 function Get(Index: integer): string;
29 procedure Put(Index: integer; Item: string);
32 destructor Destroy; override;
33 procedure SetHook(hWnd: THandle);
35 property Items[Index: Integer]: string read Get write Put; default;
36 property GestureCount: Integer read GetGestureCount;
37 property Margin: Integer read FMargin write FMargin;
38 function GetGestureStr: string;
40 property OnGestureStart: TNotifyEvent read FOnGestureStart write FOnGestureStart;
41 property OnGestureMove: TNotifyEvent read FOnGestureMove write FOnGestureMove;
42 property OnGestureEnd: TNotifyEvent read FOnGestureEnd write FOnGestureEnd;
45 function GestureProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
48 MouseGesture: TMouseGesture;
55 constructor TMouseGesture.Create;
60 FBeginGesture := False;
62 FGestureItemList := TStringList.Create;
65 destructor TMouseGesture.Destroy;
69 FGestureItemList.Free;
73 //
\83}
\83E
\83X
\83t
\83b
\83N
74 procedure TMouseGesture.SetHook(hWnd: THandle);
80 FHook := SetWindowsHookEx(WH_MOUSE, @GestureProc, 0{HInstance}, GetCurrentThreadId);
83 //
\83}
\83E
\83X
\83t
\83b
\83N
\89ð
\8f\9c
84 procedure TMouseGesture.UnHook;
88 UnhookWindowsHookEx(FHook);
92 //
\83t
\83b
\83N
\83v
\83\8d\83V
\83W
\83\83
93 function GestureProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
95 mhs: PMouseHookStruct;
97 if nCode = HC_ACTION then begin
98 mhs := PMouseHookStruct(lParam);
99 if MouseGesture.CheckAction(wParam, mhs^.pt.X, mhs^.pt.Y) then begin
104 Result := CallNextHookEx(MouseGesture.FHook, nCode, wParam, lParam);
107 function TMouseGesture.CheckAction(Message: Integer; x, y: Integer): Boolean;
116 if FBeginGesture then begin
117 //
\8d¡
\83}
\83E
\83X
\82ð
\83L
\83\83\83v
\83`
\83\83\81[
\82µ
\82Ä
\82¢
\82é
\82Ì
\82ð
\93¾
\82é
119 //
\83}
\83E
\83X
\83W
\83F
\83X
\83`
\83\83\81[
\82Ì
\91Î
\8fÛ
\82Æ
\88á
\82¤
\82Æ
\82«
\82Í
\81A
\8aJ
\95ú
\82·
\82é
120 if (hwnd <> 0) and (hwnd <> FHandle) then begin
124 dp := Point(x - FLastPoint.X, y - FLastPoint.Y);
125 sp := Point(Sign(dp.X), Sign(dp.Y));
126 if (dp.X * dp.X + dp.Y * dp.Y) > (FMargin * FMargin) then begin
127 dp := Point(Abs(dp.X), Abs(dp.Y));
128 if dp.X > dp.Y div 3 then
130 if dp.Y > dp.X div 3 then
132 AddAction(sp.X, sp.Y);
133 FLastTime := GetTickCount;
134 FLastPoint := Point(x, y);
139 WM_RBUTTONDOWN: begin
140 if (not FCancelMode) then begin
141 if ( GikoSys.Setting.GestureIgnoreContext ) then begin
142 //
\8d¡
\83}
\83E
\83X
\82ð
\83L
\83\83\83v
\83`
\83\83\81[
\82µ
\82Ä
\82¢
\82é
\82Ì
\82ð
\93¾
\82é
144 //
\83}
\83E
\83X
\83W
\83F
\83X
\83`
\83\83\81[
\82Ì
\91Î
\8fÛ
\82Æ
\88á
\82¤
\82Æ
\82«
\82Í
\81A
\8aJ
\95ú
\82·
\82é
145 if (hwnd <> 0) and (hwnd <> FHandle) then begin
149 FBeginGesture := True;
151 FLastPoint := Point(x, y);
152 FStartPoint := Point(x, y);
160 else if (FBeginGesture) then begin
161 FBeginGesture := False;
163 if FGestureItemList.Count <> 0 then begin
164 if Assigned(FOnGestureEnd) then begin
171 //
\83W
\83F
\83X
\83`
\83\83\81[
\82¶
\82á
\82È
\82©
\82Á
\82½
\8fê
\8d\87\81A
\83}
\83E
\83XDOWN,UP
\82ð
\83G
\83~
\83\85\83\8c\81[
\83g
172 mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_RIGHTDOWN, FStartPoint.X, FStartPoint.Y, 0, 0);
173 mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
180 //
\93®
\8dì
\82Ì
\92Ç
\89Á
181 procedure TMouseGesture.AddAction(sx, sy: Integer);
186 if (sx > 0) and (sy = 0) then
188 else if (sx < 0) and (sy = 0) then
196 if FGestureItemList.Count > 0 then begin
197 if Items[FGestureItemList.Count - 1] = Direction then
200 //
\83W
\83F
\83X
\83`
\83\83\81[
\8aJ
\8en
201 if Assigned(FOnGestureStart) then
202 FOnGestureStart(Self);
204 AddGesture(Direction);
205 if Assigned(FOnGestureMove) then
206 FOnGestureMove(Self);
209 //
\8c»
\8dÝ
\82Ì
\83W
\83F
\83X
\83`
\83\83\81[
\82É
\90V
\82µ
\82¢
\95û
\8cü
\82ð
\92Ç
\89Á
210 function TMouseGesture.AddGesture(Item: string): Integer;
212 Result := FGestureItemList.Add(Item);
215 //
\8ew
\92è
\82³
\82ê
\82½index
\82Ì
\93®
\82«
\82ð
\95Ô
\82·
216 function TMouseGesture.Get(Index: Integer): string;
218 Result := FGestureItemList[Index];
221 //
\8ew
\92è
\82³
\82ê
\82½index
\82Ì
\93®
\82«
\82ð
\90Ý
\92è
\82·
\82é
222 procedure TMouseGesture.Put(Index: Integer; Item: string);
224 FGestureItemList[Index] := Item;
227 //
\83W
\83F
\83X
\83`
\83\83\81[
\95¶
\8e\9a\97ñ
\82ð
\95Ô
\82·
228 function TMouseGesture.GetGestureStr: string;
233 for i := 0 to FGestureItemList.Count - 1 do
234 Result := Result + Items[i];
237 //
\83W
\83F
\83X
\83`
\83\83\81[
\82Ì
\92·
\82³
\82ð
\95Ô
\82·
238 function TMouseGesture.GetGestureCount: Integer;
240 Result := FGestureItemList.Count;
243 //
\83W
\83F
\83X
\83`
\83\83\81[
\82ð
\83N
\83\8a\83A
\82·
\82é
244 procedure TMouseGesture.Clear;
246 FGestureItemList.Clear;