Ver Mensaje Individual
  #3  
Antiguo 23-02-2011
leo007 leo007 is offline
Registrado
NULL
 
Registrado: feb 2011
Posts: 2
Reputación: 0
leo007 Va por buen camino
Muchisimas gracias ,ahi algo encontre pero no se como pasarlo para que quede como .dll y se ejecute automaticamente una vez hookeado.

No se si me expreso bien (espero que si) yo tengo un Ejecutable al cual quiero hookearle la dll y que una vez iniciado el ejecutable inicie la dll y automaticamente bloquee las teclas-

Saludos y gracias .

Codigo encontrado :
Cita:
unit Hooks;

interface

type
{ Teclas que podemos inhabilitar }
TLockableKey = (lkAltTab, lkAltEsc, lkCtrlEsc, lkAltF4, lkWin, lkApps);

procedure SetHook;
procedure ReleaseHook;

procedure LockKey(Key: TLockableKey; Lock: Boolean);

implementation

uses
Windows;

const
{
Tipo de 'gancho'

Obsérvese que la documentación de Windows que viene
con Delphi no incluye este 'gancho' sino únicamente
WH_KEYBOARD que no intercepta estas teclas.
}
WH_KEYBOARD_LL = 13;

{ Banderas para detectar las teclas ALT y CTRL }
LLKHF_ALTDOWN = $20;
LLKHF_CTRLDOWN = $8000;

type
PKbdHookInfo = ^TKbdHookInfo;
TKbdHookInfo = record
VkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
ExtraInfo: DWORD;
end;

var
Hook: HHook;
Keys: set of TLockableKey;

function KbdHook(Code: Integer; WParam, LParam: DWORD): HHook; stdcall;
var
VkCode: DWORD;
AltDown: Boolean;
CtrlDown: Boolean;

begin
if Code = HC_ACTION then
begin
VkCode := PKbdHookInfo(LParam).VkCode;
AltDown := PKbdHookInfo(LParam).Flags and LLKHF_ALTDOWN <> 0;
CtrlDown := GetAsyncKeyState(VK_CONTROL) and LLKHF_CTRLDOWN <> 0;

if (VkCode = VK_TAB) and AltDown and (lkAltTab in Keys) then
begin
Result := 1;
exit;
end;

if (VkCode = VK_ESCAPE) then
begin
if AltDown and (lkAltEsc in Keys) then
begin
Result := 1;
exit;
end;

if CtrlDown and (lkCtrlEsc in Keys) then
begin
Result := 1;
exit;
end;
end;

if (VkCode = VK_F4) and AltDown and (lkAltF4 in Keys) then
begin
Result := 1;
exit;
end;

if ((VkCode = VK_LWIN) or (VkCode = VK_RWIN)) and (lkWin in Keys) then
begin
Result := 1;
exit;
end;

if (VkCode = VK_APPS) and (lkApps in Keys) then
begin
Result := 1;
exit;
end;
end;

Result := CallNextHookEx(Hook, Code, WParam, LParam);
end;

procedure SetHook;
begin
Hook := SetWindowsHookEx(WH_KEYBOARD_LL, @KbdHook, HInstance, 0);
end;

procedure ReleaseHook;

begin
if Hook <> 0 then UnhookWindowsHookEx(Hook);
end;

procedure LockKey(Key: TLockableKey; Lock: Boolean);
begin
if Lock then Include(Keys, Key) else Exclude(Keys, Key);
end;

initialization
Hook := 0;
Keys := [];

finalization
ReleaseHook;
end.
Fuente :roman.clubdelphi
Responder Con Cita