Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetWindowsHookEx: Can I control all keyboard and mouse actions?

777 views
Skip to first unread message

Alexandre Duran Mertens

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to
I need to delete/control all keyboard and mouse action in my application.

I see that SetWindowsHookEx with WH_KEYBOARD and WH_MOUSE parameters can get
and control all keyboard and mouse message for the application or system.

It's work fine for application but no for system. My hook function is in a
DLL, and main form in a delphi project.

The comjplete instruction is
"MouseHook:=setWindowsHookEx(WH_MOUSE,@HookCode,0,0);"

Is it correct?


Alex.

Pieter Zijlstra

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to

Alexandre Duran Mertens wrote:
<<
I see that SetWindowsHookEx with WH_KEYBOARD and WH_MOUSE parameters can get
and control all keyboard and mouse message for the application or system.
It's work fine for application but no for system. My hook function is in a
DLL, and main form in a delphi project.

The complete instruction is
"MouseHook:=setWindowsHookEx(WH_MOUSE,@HookCode,0,0);"

Is it correct?
>>

Yes,...and no

The function call itself is correct but...
<quote>
Creating a Windows systems hook requires special handling
under Win32, since the dll must be mapped (on the fly) into
the process space of every application that receives keystrokes.
<end quote>

To get the rest of this interresting story and a sample from
Joe C.Hecht goto www.deja.com search page and do a
PowerSearch for "Global keyboard hooks" in the same forum
as your now in (so b.p.d.winapi).

- Pieter

Torjei Kvinen

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to

"Alexandre Duran Mertens" <csdesa...@nostracom.com> wrote in message

> I need to delete/control all keyboard and mouse action in my application.
>

> I see that SetWindowsHookEx with WH_KEYBOARD and WH_MOUSE parameters can
get
> and control all keyboard and mouse message for the application or system.
>
> It's work fine for application but no for system.


Here is a system wide keyboard and mouse hook example:
http://home.sol.no/~t-kvine/hook.zip


--
Regards
Torjei Kvinen

Daniel G. Schaer

unread,
Jan 27, 2000, 3:00:00 AM1/27/00
to
Hi Torjei;

> Here is a system wide keyboard and mouse hook example:
> http://home.sol.no/~t-kvine/hook.zip
>

I am trying to study this example and it seams to work fine. My question is,
into the hooked procedure, is there a parameter for reading which button is
pressed? ... or the only way is to see the KeyState of VK_* you want?

Thanks

Daniel

Torjei Kvinen

unread,
Jan 27, 2000, 3:00:00 AM1/27/00
to

"Daniel G. Schaer" <sch...@lex-doctor.com> wrote in message

> I am trying to study this example and it seams to work fine. My question
is,
> into the hooked procedure, is there a parameter for reading which button
is
> pressed? ... or the only way is to see the KeyState of VK_* you want?


Keyboard hook:
wParam specifies the virtual-key code.

case wParam of
VK_RETURN:
begin
end;
ord('A'):
begin
end;
VK_F1:
begin
end;
end;


Mouse hook:
wParam specifies the mouse message.

case wParam of
WM_LBUTTONDOWN:
begin
end;
WM_LBUTTONUP:
begin
end;
end;


--
Regards
Torjei Kvinen


0 new messages