How to lock a keyboard , but not mouse ! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to lock a keyboard , but not mouse !

Albi91VlAlbi91Vl Posts: 9Member
I want to know if there is any kind of hack that locks the keyboard but i want to use it from a program made in pascal.

Comments

  • _Atex__Atex_ Posts: 163Member
    : I want to know if there is any kind of hack that locks the keyboard
    : but i want to use it from a program made in pascal.
    :

    There are two ways to disable the keyboard. The preferable one is to hijack the keyboard interrupt ( int 9h ) by redirecting to a routine which will only generate an EOI ( end of interrupt ) signal to the 8259 programmable interrupt controller chip. There is an other way, a quick and dirty method by turning the bit 1 on port 21h, which is the programmable interrupt controllers mask register. ( Bit 0 is IRQ0, Bit 1 is IRQ1 (<-- the keyboard ), Bit 2 is IRQ2 ( cascade for IRQ8..15), Bit 3 is IRQ3 ( COM2/COM4 )... and so on...) There is a problem, that is not possible to flush the keyboard buffer after re-enabling the keyboard using this method :-( See example:[code][blue]uses crt,dos;

    var old_keyb_int:procedure;

    procedure keyb_enable;assembler;
    asm
    in al,21h { get value from port 21h }
    and al,11111101b { flip bit 1 off }
    out 21h,al { write value back to }
    end;

    procedure keyb_disable;assembler;
    asm
    in al,21h
    or al,00000010b { turn on bit 1 }
    out 21h,al
    end;

    procedure new_keyb_int;assembler;
    asm
    push ax { save AX }
    mov al,20h
    out 20h,al { send EOI to programmable interrupt controller }
    pop ax { restore AX }
    iret { return from interrupt }
    end;

    procedure delay15; { delay for 15 sec. }
    var i:byte;
    begin
    writeln('Keyboard disabled for 15 seconds');
    for i:=15 downto 1 do begin
    write(#8#8#8,i,#32);
    delay(1000);
    if keypressed then begin
    writeln('Keypress detected...'); { <-- this shouldn't happen }
    readkey;
    end;
    end;
    end;


    begin
    {#### Method 1 ####}
    keyb_disable;
    delay15;
    keyb_enable;
    while keypressed do readkey; { <-- attempt to flush keyboard buffer }
    writeln(#13#10'Keyboard enabled');
    readln;



    {#### Method 2 ####}
    getintvec($9,@old_keyb_int);
    setintvec($9,@new_keyb_int);
    delay15;
    setintvec($9,@old_keyb_int);
    writeln(#13#10'Keyboard enabled');
    readln;
    end.[/code]
Sign In or Register to comment.