Einzelnen Beitrag anzeigen

Benutzerbild von fiasko
fiasko

Registriert seit: 10. Dez 2002
Ort: Dresden
506 Beiträge
 
#24

Re: STRG + ALT + ENTF sperren

  Alt 9. Mai 2004, 21:56
Ich verwende folgende Kode für ne DLL die das macht:

Delphi-Quellcode:
library foo;

uses
  Windows,
  Messages,
  SysUtils;

var
  g_hHookKbdLL: HHOOK = 0;

{ This only works with on Win NT 5.0 (formely known as Win 2000) upwards,
  but Delphi's WinAPI is somethink like obselete in this manner. }

const
  WH_KEYBOARD_LL = 13;
  LLKHF_ALTDOWN = 0x00000020;
type
  { Structure used by WH_KEYBOARD_LL }
  KBDLLHOOKSTRUCT = record
                      vkCode: DWORD;
                      scanCode: DWORD;
                      flags: DWORD;
                      time: DWORD;
                      dwExtraInfo: DWORD;
                    end;
  PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;

{ Trap task-switching keys by returning without passing along. }
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+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 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;

exports
  DisableTaskKeys name 'DisableTaskKeys';

end.
Thomas Liske
Posts comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
  Mit Zitat antworten Zitat