Registriert seit: 26. Nov 2003
Ort: Berlin
343 Beiträge
Delphi 2006 Professional
|
Re: STRG+ESC ... Sperren (Hooks?)
31. Jan 2005, 00:16
@Luckie: Irgendwie musste ich grinsen... Nahezu das selbe hast du auch mal zu mir gesagt
Ich brauchte das ebenfalls mal und habe daraus diese DLL gemacht: (kA woher ich das hatte)
Delphi-Quellcode:
library Project1;
uses
Windows,
Messages,
SysUtils,
Registry;
var
g_hHookKbdLL: HHOOK = 0;
g_hHookKbd: HHOOK = 0;
HookHandle: Cardinal = 0;
WindowHandle: Cardinal = 0;
const
WH_KEYBOARD_LL = 13;
LLKHF_ALTDOWN = 32;
WM_HOOKMESSAGEID = WM_USER + 7328;
type
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
scanCode: DWORD;
flags: DWORD;
time: DWORD;
dwExtraInfo: DWORD;
end;
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
function MyTaskKeyHookLL(nCode: Integer; wp: WPARAM; lp: LPARAM): LRESULT; stdcall;
var
pkh: PKBDLLHOOKSTRUCT;
bCtrlKeyDown: BOOL;
begin
pkh:=PKBDLLHOOKSTRUCT(lp);
if nCode=HC_ACTION then
begin
bCtrlKeyDown := GetAsyncKeyState(VK_CONTROL) shr ((sizeof(SHORT) * 8) - 1)<>0;
// Ctrl+Esc
if ((pkh^.vkCode=VK_ESCAPE) and bCtrlKeyDown) or
// Alt+F4
((pkh^.vkCode=VK_F4) and (pkh^.flags and LLKHF_ALTDOWN=LLKHF_ALTDOWN)) or
// Alt+TAB
((pkh^.vkCode=VK_TAB) and (pkh^.flags and LLKHF_ALTDOWN=LLKHF_ALTDOWN)) or
// Alt+Esc
((pkh^.vkCode=VK_ESCAPE) and (pkh^.flags and LLKHF_ALTDOWN=LLKHF_ALTDOWN)) or
// Start Menu
((pkh^.vkCode=VK_LWIN) or (pkh^.vkCode=VK_RWIN)) then
begin
result:=1;
exit;
end;
end;
result:=CallNextHookEx(g_hHookKbdLL, nCode, wp, lp);
end;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
case nCode < 0 of
TRUE: exit;
FALSE: Postmessage(WindowHandle,WM_HOOKMESSAGEID,0,0);
end;
end;
function DisableTaskKeys(bDisable: bool): bool; stdcall;
begin
if bDisable then
begin
if g_hHookKbdLL=0 then
g_hHookKbdLL := SetWindowsHookEx(WH_KEYBOARD_LL, MyTaskKeyHookLL, HInstance, 0);
end
else
if g_hHookKbdLL<>0 then
begin
UnhookWindowsHookEx(g_hHookKbdLL);
g_hHookKbdLL := 0;
end;
result:=g_hHookKbdLL<>0;
end;
function EnableKeyboardCheck(HWND: Cardinal; Activate: Boolean): boolean; stdcall;
begin
if Activate = TRUE then
begin
Result := False;
if HookHandle = 0 then begin
HookHandle := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyboardHookProc, HInstance, 0);
WindowHandle := Hwnd;
Result := TRUE;
end;
end
else
begin
Result := UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;
end;
exports
DisableTaskKeys, EnableKeyboardCheck;
begin
end.
Christian Reber
|
|
Zitat
|