用鼠标钩子吧,应该可行。
{-----------------------------------------------------------------------------
Procedure: MouseHookCallBack
Author: Chinbo(Chinbo)
Date: 02-八月-2002
Arguments: Code: integer; Msg: WPARAM; MouseHook: LPARAM
Result: LRESULT
-----------------------------------------------------------------------------}
{$IFDEF WIN32}
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM):
LRESULT; stdcall;
{$ELSE}
function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint):
longint; export;
{$ENDIF}
begin
if Code = HC_ACTION then
{触发鼠标移动事件,可以配合FindVCLWindow函数知道是哪个控件};
Result := CallNextHookEx(whMouse, Code, Msg, MouseHook);
end;
{-----------------------------------------------------------------------------
Procedure: CreateHooks
Author: Chinbo(Chinbo)
Date: 02-八月-2002
Arguments: None
Result: None
-----------------------------------------------------------------------------}
procedure CreateHooks;
{-----------------------------------------------------------------------------
Procedure: GetModuleHandleFromInstance
Author: Chinbo(Chinbo)
Date: 02-八月-2002
Arguments: None
Result: THandle
-----------------------------------------------------------------------------}
function GetModuleHandleFromInstance: THandle;
var
s: array[0..512] of char;
begin
GetModuleFileName(hInstance, s, sizeof(s) - 1);
Result := GetModuleHandle(s);
end;
begin
if not HookActive then
begin
whMouse := SetWindowsHookEx(WH_MOUSE, MouseHookCallBack,
GetModuleHandleFromInstance,
{$IFDEF WIN32}GetCurrentThreadID{$ELSE}GetCurrentTask{$ENDIF});
whKeyboard := SetWindowsHookEx(WH_KEYBOARD, KeyboardHookCallBack,
GetModuleHandleFromInstance,
{$IFDEF WIN32}GetCurrentThreadID{$ELSE}GetCurrentTask{$ENDIF});
end;
end;
{-----------------------------------------------------------------------------
Procedure: RemoveHooks
Author: Chinbo(Chinbo)
Date: 02-八月-2002
Arguments: None
Result: None
-----------------------------------------------------------------------------}
procedure RemoveHooks;
begin
if HookActive then
try
UnhookWindowsHookEx(whKeyboard);
UnhookWindowsHookEx(whMouse);
finally
whKeyboard := 0;
whMouse := 0;
end;
end;