procedure Register;
begin
RegisterComponents('Rarnu Components', [TRaKeyBlock]);
end;
{ TRaKeyBlock }
constructor TRaKeyBlock.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure EnableCTRLALTDEL(YesNo: Boolean);
const
sRegPolicies = '\Software\Microsoft\Windows\CurrentVersion\Policies';
begin
with TRegistry.Create do
try
RootKey := HKEY_CURRENT_USER;
if OpenKey(sRegPolicies + '\System\', True) then
begin
case YesNo of
false:
begin
WriteInteger('DisableTaskMgr', 1); //任务管理
WriteInteger('DisableLockWorkstation', 1); //用户锁定计算机
WriteInteger('DisableChangePassword', 1); //用户更改口令
end;
True:
begin
WriteInteger('DisableTaskMgr', 0);
WriteInteger('DisableLockWorkstation', 0);
WriteInteger('DisableChangePassword', 0);
end;
end;
end;
CloseKey;
if OpenKey(sRegPolicies + '\Explorer\', True) then
begin
case YesNo of
false:
begin
WriteInteger('NoChangeStartMenu', 1); //开始菜单
WriteInteger('NoClose', 1); // 关闭系统菜单
WriteInteger('NoLogOff', 1); //注销菜单
WriteInteger('NoRun', 1); //运行菜单
WriteInteger('NoSetFolders', 1); //设置菜单
end;
True:
begin
WriteInteger('NoChangeStartMenu', 0);
WriteInteger('NoClose', 0);
WriteInteger('NoLogOff', 0);
WriteInteger('NoRun', 0);
end;
end;
end;
CloseKey;
finally
Free;
end;
end;
function LowLevelKeyboardFunc(nCode: INTEGER; w_Param: WPARAM;
l_Param: LPARAM): LRESULT; stdcall;
var
boolKey: Boolean;
p: PKBDLLHOOKSTRUCT;
const
VK_SLEEP = $5F;
VK_POWER = $5E;
begin
boolKey := false;
if nCode = HC_ACTION then
begin
case w_Param of
WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP:
begin
p := PKBDLLHOOKSTRUCT(l_Param);
//---------!-~------------------------------------------------
{ if ((GetAsyncKeyState(VK_RBUTTON) and $8000) <> 0) then boolKey := true;
if (CHAR(p.vkCode) >= '!') and (CHAR(p.vkCode) <= '~') and
((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := true;
if (p.vkCode = VK_SPACE) and
((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := true; }
//---------F1-F12 ----------------------------------------------
{ if (p.vkCode = VK_F1) or (p.vkCode = VK_F2) or (p.vkCode = VK_F3) or
(p.vkCode = VK_F4) or (p.vkCode = VK_F5) or (p.vkCode = VK_F6) or
(p.vkCode = VK_F7) or (p.vkCode = VK_F8) or (p.vkCode = VK_F9) or
(p.vkCode = VK_F10) or (p.vkCode = VK_F11) or (p.vkCode = VK_F12) then boolKey := true;
if ((p.vkCode = VK_F1) or (p.vkCode = VK_F2) or (p.vkCode = VK_F3) or
(p.vkCode = VK_F4) or (p.vkCode = VK_F5) or (p.vkCode = VK_F6) or
(p.vkCode = VK_F7) or (p.vkCode = VK_F8) or (p.vkCode = VK_F9) or
(p.vkCode = VK_F10) or (p.vkCode = VK_F11) or (p.vkCode = VK_F12)) and
(((GetKeyState(VK_MENU) and $8000) <> 0) or ((GetKeyState(VK_CONTROL) and $8000) <> 0) or ((GetKeyState(VK_SHIFT)and$8000) <> 0)) then boolKey := true; }
//-------系统热键---------------------------------------------
//WIN(Left or Right)+APPS
if aBWA then
begin
if (p.vkCode = VK_LWIN) or (p.vkCode = VK_RWIN) or (p.vkCode = VK_APPS) then boolKey := True;
end;
//CTRL+ESC
if aBCE then
begin
if (p.vkCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := True;
end;
//ALT+TAB
if aBAT then
begin
if (p.vkCode = VK_TAB) and ((GetAsyncKeyState(VK_MENU) and $8000) <> 0) then boolKey := True;
end;
//ALT+ESC
if aBAE then
begin
if (p.vkCode = VK_ESCAPE) and ((p.flags and LLKHF_ALTDOWN) <> 0) then boolKey := True;
end;
//CTRL+ENTER
if aBCR then
begin
if (p.vkCode = VK_RETURN) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := True;
end;
//CTRL+ALT+ENTR
if aBCAE then
begin
if (p.vkCode = VK_RETURN) and ((p.flags and LLKHF_ALTDOWN) <> 0) and ((GetKeyState(VK_CONTROL) and $8000) <> 0) then boolKey := True;
end;
//POWER
if aBP then
begin
if (p.vkCode = VK_POWER) then boolKey := True;
end;
//SLEEP
if aaBS then
begin
if (p.vkCode = VK_SLEEP) then boolKey := True;
end;
//-------------------------------------------------------------------------------------------------------------------------------------
//Custom
if aBCK then
begin
if (p.vkCode = aCKC) then boolKey := True;
end;
//-------------------------------------------------------------------------------------------------------------------------------------
//如果有其他要屏闭的键,添加在此处
end;
end;
end;
//捕获这些组合键,按键消息由自己处理,必须返回 1
if boolKey then begin Result := 1; Exit end;
//其他的按键,交由别的线程处理(过滤)
Result := CallNextHookEx(0, nCode, w_Param, l_Param);
end;
destructor TRaKeyBlock.Destroy;
begin
Enabled:=false;
inherited Destroy;
end;
procedure TRaKeyBlock.SetEnabled(const Value: Boolean);
begin
fEnabled := Value;
//设置可用
case fEnabled of
True:
begin
if hhkNTKeyboard <> 0 then Exit;
hhkNTKeyboard := SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardFunc, HInstance, 0);
if fBCAD then
begin
EnableCTRLALTDEL(false);
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
end;
false:
begin
if hhkNTKeyboard = 0 then Exit;
UnhookWindowsHookEx(hhkNTKeyboard); // 卸载钩子
EnableCTRLALTDEL(true);
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
hhkNTKeyboard := 0;
end;
end;
end;