본문 바로가기

카테고리 없음

[시스템] 윈도우즈 전체의 키보드 입력 금지

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

{IRQNum Tabelle:
   Master:
   IRQ 1: Keyboard

  Slave:
   IRQ 12: Mouse

OnOff:
   True  = it is on
   False = it is off, cant be used}
procedure IRQ_Control(IRQNum: Byte; OnOff: Boolean);
var
  NearIRQNum : Byte;
  Port       : Word;
  Mask       : Byte;
begin
  NearIRQNum := IRQNum;

  if IRQNum < 8 then
    Port := $21
  else
  begin
    Port := $A1;
    Dec(NearIRQNum, 8);
  end;

  Mask := 128;
  Mask := Mask shr (7-NearIRQNum);

  if OnOff then
  asm
    mov   dx, Port  // activate irq
    in    al, dx
    not   Mask
    and   al, Mask
    out   dx, al
  end
  else
  asm
    mov   dx, Port  // deactivate it
    in    al, dx
    or    al, Mask
    out   dx, al
  end;
end;

function FlushKeyBuffer: boolean;
var
  KeyStateBuff: TKeyboardState;
begin
  FillChar(KeyStateBuff, SizeOf(KeyStateBuff), #0);
  Result := SetKeyboardState(KeyStateBuff);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  IRQ_Control(1, False); // 키보드 입력 금지
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  FlushKeyBuffer; // 키보드 버퍼를 flush 한다
  IRQ_Control(1, True); // 키보드 입력 허용
end;

end.