|
var
Form1: TForm1;
RecordHook: HHOOK; // Hook handle
Timer: Integer = 0; // Cumulative time, in seconds
State: Boolean = TRUE; // Is it'online'
//=========
Msg: TMsg;
WndClass: TWndClass;
HMainWnd: HWND;
implementation
{$R *.dfm}
// form function
function WindowProc(hWnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
MousePos: TPoint; // Mouse position
begin
case (uMsg) of
WM_TIMER:
if (State = TRUE) then
begin
Inc(Timer);
if (Timer >= 5) then // think to leave after 5 seconds
begin
State := FALSE;
form1.Button1.Caption:='Leave';
end;
end;
end;
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
// hook function
function JournalRecordProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
Msg: LongWord;
begin
if (nCode = HC_ACTION) then // lParam points to the message structure
begin
Msg := PEventMsg(lParam)^.message;
if ((Msg >= WM_KEYFIRST) and (Msg <= WM_KEYLAST)) or // keyboard message
((Msg >= WM_MOUSEFIRST) and (Msg <= WM_MOUSELAST)) then // mouse message
begin
Timer := 0;
if (State = FALSE) then //'Leave' ->'Online'
begin
State := TRUE;
form1.Button1.Caption:='Come back';
end;
end;
end;
Result := CallNextHookEx(RecordHook, nCode, wParam, lParam); // next hook
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// uninstall hook
UnHookWindowsHookEx(RecordHook);
// delete clock
KillTimer(HMainWnd, 6);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
// install the clock
SetTimer(HMainWnd, 6, 1000, nil);
// install hook
RecordHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalRecordProc, HInstance, 0);
// message loop
while GetMessage(Msg, 0, 0, 0) do
begin
if (Msg.message = WM_CANCELJOURNAL) then // need to hook again at this time
RecordHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalRecordProc, HInstance, 0)
else
DispatchMessage(Msg);
end;
end;
end.
Probably so... |
|