锁键盘procedure TForm1.Button1Click(Sender: TObject);
begin
  Asm    //封锁20端口
  IN AL,21H
  OR AL,02H
  OUT 21H,AL
  end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
 Asm         //解锁20端口
 IN AL,21H
 AND AL,0FDH
 OUT 21H,AL
 end;
end;

解决方案 »

  1.   

    再给你一个例子:
    Library KillKB;Uses Wintypes, WinProcs
    {$IFNDEF VER80}
      ,Win31
    {$ENDIF}
      ;
    Var
      oldHook: HHook;Function KbHook( code: Integer; wparam: Word; lparam: LongInt ): LongInt;
      export;
    Begin
      If code < 0 Then
        KbHook := CallNextHookEx( oldHook, code, wparam, lparam )
      Else
        KbHook := 1;
    End; { KbHook }Function DisableKeyboard: Boolean; export;
    Begin  oldHook := SetWindowsHookEx( WH_KEYBOARD, KbHook, HInstance, 0 );
      DisableKeyboard := oldHook <> 0;
    End;Procedure EnableKeyboard; export;
    Begin
      If oldHook <> 0 Then Begin
        UnhookWindowshookEx( oldHook );
        oldHook := 0;
      End; { If }
    End;exports
    DisableKeyboard index 1,
    EnableKeyboard index 2;Begin
      oldHook := 0;
    End.有一些组合键不能屏蔽掉,例如Ctrl+Alt+Del!
      

  2.   

    补充:这个只在win98下有用。
      

  3.   

    阻塞键盘鼠标输入:
    BlockInput(true); 
    BlockInput(False); ================================================================
    一颗红心向前看,为了革命两茫然,不好意思才囊尽,只能说上一点点。
    ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
    ★    我踢  我踢   我踢  我踢  我踢  我踢  我踢  我踢  我踢   ★
    ★    你UP  你UP   你UP  你UP  你UP  你UP  你UP  你UP  你UP   ★
    ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
    ================================================================
      

  4.   

    我也有这个问题,我用C写了一个动态库,能锁定,但是有个问题,就是不能锁定CTRL+ALT+DEL三个键,cg1120(代码最优化-§人在爱情的空窗期要个梦§) 的代码我也用过,也不能锁定这三个键,这个问题挺头痛的!
      

  5.   

    SystemParametersInfo(Spi_screensaverrunning,1,@temp,0);  //屏蔽系统功能键
      

  6.   

    SystemParametersInfo(Spi_screensaverrunning,1,@temp,0);  //屏蔽系统功能键
      

  7.   

    锁死键盘和鼠标unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.dfm}
    // 检测函数是否存在于系统库中(dll)
    function FuncAvail (VLibraryname, VFunctionname: string; var VPointer: Point
    er):
    boolean;
    var
      Vlib: tHandle;
    begin
      Result := false;
      VPointer := NIL;
       if LoadLibrary(PChar(VLibraryname)) = 0 then
          exit;
       Vlib := GetModuleHandle(PChar(VLibraryname));
       if Vlib <> 0 then
       begin
        VPointer := GetProcAddress(Vlib, PChar(VFunctionname));
        if VPointer <> NIL then
           Result := true;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
       xBlockInput : function(Block: BOOL): BOOL; stdcall;
    begin
      if FuncAvail('USER32.DLL', 'BlockInput', @xBlockInput) then
      begin
       xBlockInput(true);    // 锁死鼠标和键盘
       Sleep(15000);         // 等待 15 秒
       xBlockInput(false);   // 恢复
      end;
    end;
    end.
      

  8.   

    begin
         KHK:=SetWindowsHookex(WH_JOURNALPLAYBACK,@HookProc,HInstance,0);//开始锁定
         SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @tmp, 0);//屏蔽Windows的系统键Ctrl-Alt-Tab,Ctrl-Esc,Alt-Tab等
       end;