function GetSysFocus: integer;
Var
hFgWin, FgThreadID, hFocusWin: integer;
Begin
hFgWin := GetForegroundWindow;
FgThreadID := GetWindowThreadProcessID(hFgWin, nil);
If AttachThreadInput(GetCurrentThreadID, FgThreadID, true) Then
Begin
hFocusWin := GetFocus;
result := GetFocus;
AttachThreadInput(GetCurrentThreadID, FgThreadID, False);
End
else
result := GetFocus;
End;