Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

tsr program for hot keying inseredt text from configuration file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBDos tsr program for hot keying inseredt text from configuration file

    This tsr program will wake from F12 KEY pressed and insert characters preset from a configuration file.
    The screen will be cleared then the hotkey with an abbreviated description for the hot key.
    256 characters can be inserted in the keyboard buffer in windows 7 machine.

    Only problem is I am having trouble with an extra part to this program where it will print the screen to a LPT1 LPT2 or LPT3 printer.
    A print screen dialog will popup if the key configuration file is not read for whatever purpose.
    This is actually a narrowed down version of a program that i wrote for our dos software we are using.
    In my version, there is only one place where we want the hot keys for memos and this program checks to make sure we are at that srceen.
    I left in some code for others to do the same with hard coded version.
    If you want to print out the screen to a LPT1 to LPT3 device you can just use "programname LPTX" for you command line.
    We use "programname LPT2 C:\directory\prgram.cfg" as a catch all in one TSR to print a screen or hot key input on a single character.
    The characters can have a an embedded carriage return by placing 2 consecutive periods at the end of the keys to be inserted with press of a single hot key after pressing the F12 Key.
    The next version that i write will just display somewhere on the screen it is in hotkey mode after pressing the F12 Key maybe a "?" key will show the hot keys if the user does not
    have a list of the hot keys in another window.
    The hot keys are 0-9 and A-Z but more could be added if needed but 36 is enough for now.
    Not on my test machine but on a production machine, printing the screen did create a problem that the error routine that i wrote did not work if a printer is not available or not redirected.
    If you need that to be better. You can do it or just take it out all together or just do not put LPTX on the command line.

    Code:
    REM TSRXNOTE.BAS
    REM POWERBASIC SOURCE CODE
    REM VERSION 08-05-2018
    REM COMPILED WITH POWERBASIC 3.5 FOR DOS
    $CPU 80386 'program works on any CPU
    $OPTIMIZE SPEED 'make smallest possible executable
    $DIM ALL
    $DEBUG MAP OFF 'turn off map file generation
    $DEBUG PBDEBUG OFF 'don't include pbdebug support in our executable
    $LIB COM OFF 'turn off PowerBASIC's communications library.
    $LIB CGA OFF 'turn off PowerBASIC's CGA graphics library.
    $LIB EGA OFF 'turn off PowerBASIC's EGA graphics library.
    $LIB FULLFLOAT OFF 'turn off PowerBASIC's floating point support.
    $ERROR BOUNDS ON  'turn on bounds checking
    $ERROR NUMERIC OFF 'turn off numeric checking
    $ERROR OVERFLOW OFF 'turn off overflow checking
    $ERROR STACK OFF 'turn off stack checking
    $COM 0 'set communications buffer to nothing
    $STRING 16 'set largest string size at 16k
    $STACK 4096 'let's use a 2k stack
    $SOUND 1 'smallest music buffer possible
    $DYNAMIC 'all arrays will be dynamic by default
    $OPTION CNTLBREAK OFF 'don't allow Ctrl-Break to exit program
    $COMPILE EXE 'this tells PB to make a standalone EXE
    
    $EVENT OFF
    
    DIM ICOUNTER AS LONG
    DIM INPUTVARIABLE AS LONG
    
    DIM CSRLINEX AS INTEGER
    DIM CURLINEY AS INTEGER
    DIM IPRINTDEVICE AS LONG
    DIM IREADPARMFILE AS LONG
    DIM PBUFFER AS BYTE PTR
    DIM SBUFFER AS BYTE PTR
    DIM ABSOLUTE Video( 3999 ) AS BYTE AT &HB800
    DIM ICARRIAGERETURNWANTED(1 TO 36) AS LONG
    DIM SKEYSTOINSERTDESCRIPTION (1 TO 36) AS STRING
    DIM SKEYSTOINSERT (1 TO 36) AS STRING
    
    DIM SLINES(26) AS STRING
    DIM SLINESNUMBER(0 TO 10) AS STRING
    DIM STEXTTOFIND AS STRING
    DIM SCOMMANDLINE AS STRING
    DIM SPRINTDEVICE AS STRING
    DIM SSCREENTEXT AS STRING
    DIM SUPPERSCREENTEXT AS STRING
    DIM SFULLSCREEN AS STRING
    DIM SPARMFILE AS STRING
    DIM SVALIDKEYINPUT AS STRING
    DIM ICR AS LONG
    DIM ICONFIGFILEREAD AS LONG
    
    SHARED ICONFIGFILEREAD
    SHARED ICR
    SHARED IREADPARMFILE
    SHARED ICARRIAGERETURNWANTED()
    SHARED SKEYSTOINSERTDESCRIPTION ()
    SHARED SKEYSTOINSERT ()
    SHARED SPARMFILE
    SHARED SVALIDKEYINPUT
    
      SSCREENTEXT = SPACE$( 1999 )
      SUPPERSCREENTEXT = SPACE$( 1999 )
      SFULLSCREEN = SPACE$( 3999 )
    
      SCOMMANDLINE=UCASE$(TRIM$(COMMAND$))
      SCOMMANDLINE= " "+SCOMMANDLINE+" "
      IF INSTR(SCOMMANDLINE," LPT") THEN
           FOR ICOUNTER=0& TO 9&
               IF INSTR(SCOMMANDLINE," LPT"+ TRIM$(STR$(ICOUNTER)) +" ") THEN SPRINTDEVICE="LPT"+TRIM$(STR$(ICOUNTER)):IPRINTDEVICE=1&
           NEXT ICOUNTER
      END IF
      IF IPRINTDEVICE THEN
         SCOMMANDLINE=" "+TRIM$(REMOVE$(SCOMMANDLINE,SPRINTDEVICE))+" "
         IF INSTR(" LPT1 LPT2 LPT3 "," "+TRIM$(SPRINTDEVICE)+" ")=0% THEN SPRINTDEVICE="":IPRINTDEVICE=0&
      END IF
    
      SCOMMANDLINE=TRIM$(SCOMMANDLINE)
      IF (LEN(SCOMMANDLINE)>4) AND (INSTR(SCOMMANDLINE,":\") = 2%) THEN  
            SPARMFILE=DIR$(SCOMMANDLINE)
            IF "\"+SPARMFILE<>RIGHT$(SCOMMANDLINE,LEN(SPARMFILE)+1) THEN
               SPARMFILE="":IREADPARMFILE=0&
               ELSE
               SPARMFILE=SCOMMANDLINE
               IREADPARMFILE=1&
            END IF
      END IF
      IF IPRINTDEVICE+IREADPARMFILE=0 THEN
         PRINT "commandline usage eg: LPT1 to LPT3 and/or full parameter filename with drive letter"
         PRINT "See program hlp file "
         STOP
      END IF
      SCOMMANDLINE=""
      MEMPACK
      IF IREADPARMFILE THEN CALL READPARMETERFILE
      SPARMFILE=""
    
     IF LEN(SPRINTDEVICE) THEN PRINT "press F12 key to print the screen to "+SPRINTDEVICE
    MEMPACK
    
    REM ICOUNTER USED HERE COULD BE X&
      ICOUNTER = SETMEM( -700000 ) 'release unused memory
      POPUP KEY CHR$(0,&H58,247) ' F12 is the hot key
    
    
      PRINT "loaded TSRXNOTE.EXE"
      POPUP SLEEP ' before going to sleep
    
     WHILE 1 = 1
         SBUFFER = STRPTR32( SSCREENTEXT )
         PBUFFER = STRPTR32( SUPPERSCREENTEXT )
         FOR ICOUNTER = 0& TO 3999& STEP 2
             @SBUFFER = Video( ICOUNTER )
             @PBUFFER = @SBUFFER
             IF @PBUFFER = >96 AND @PBUFFER = < 123 THEN @PBUFFER = @PBUFFER-32
             INCR PBUFFER
             INCR SBUFFER
         NEXT ICOUNTER
    
        CSRLINEX = CSRLIN
        CURLINEY = POS
        IF ICONFIGFILEREAD=0& THEN GOTO DONOTDISPLAY
    
    
    rem **********************************************************************************************
    rem **********************************************************************************************
    rem  you can make this program only popup the hot keys by reading the screen and filtering on certain words
    rem
    rem  IF CSRLINEX>21 THEN GOTO DONOTDISPLAY
    rem  IF CSRLINEX<12 THEN GOTO DONOTDISPLAY
    rem
    rem ICOUNTER=0&
    rem IF INSTR( SUPPERSCREENTEXT, "words 1 on screen ")>0& THEN INCR ICOUNTER
    rem IF INSTR( SUPPERSCREENTEXT, "words 2 on screen ")>0& THEN INCR ICOUNTER
    rem IF INSTR( SUPPERSCREENTEXT, "words 3 on screen ")>0& THEN INCR ICOUNTER
    rem IF INSTR( SUPPERSCREENTEXT, "words 4 on screen ")>0& THEN INCR ICOUNTER
    rem IF INSTR( SUPPERSCREENTEXT, "words 5 on screen ")>0& THEN INCR ICOUNTER
    rem IF INSTR( SUPPERSCREENTEXT, "words 6 on screen ")>0& THEN INCR ICOUNTER
    rem IF ICOUNTER<2& THEN GOTO DONOTDISPLAY
    rem **********************************************************************************************
    rem **********************************************************************************************
    
    
    
    REM READ THE FULL SCREEN
        SBUFFER = STRPTR32( SFULLSCREEN )
        FOR ICOUNTER = 0& TO 3999&
            @SBUFFER = Video( ICOUNTER )
            INCR SBUFFER
        NEXT ICOUNTER
    
    REM CLEAR THE SCREEN
        FOR ICOUNTER = 0 TO 3999
          Video( ICOUNTER )=32
          INCR ICOUNTER
          Video( ICOUNTER )=07
        NEXT ICOUNTER
    
    rem **********************************************************************************************
    rem **********************************************************************************************
    rem  if you need to place words on the original screen you can do something like this
    rem
    rem   SBUFFER = STRPTR32( SFULLSCREEN )+160
    rem   FOR ICOUNTER = 0 TO 479
    rem       Video( ICOUNTER )=@SBUFFER
    rem       INCR SBUFFER
    rem   NEXT ICOUNTER
    rem
    rem  SBUFFER = STRPTR32( SFULLSCREEN )+1440
    rem   FOR ICOUNTER = 480 TO 799
    rem       Video( ICOUNTER )=@SBUFFER
    rem       INCR SBUFFER
    rem   NEXT ICOUNTER
    rem **********************************************************************************************
    rem **********************************************************************************************
    
        FOR ICOUNTER=1 TO 5
            LOCATE ICOUNTER+5,1,1,1,1
            PRINT " "+SKEYSTOINSERTDESCRIPTION(ICOUNTER)+"  "+SKEYSTOINSERTDESCRIPTION(ICOUNTER+5);
        NEXT ICOUNTER
        LOCATE 11,1,1,1,1
        PRINT STRING$(79,"-");
    
        FOR ICOUNTER=11 TO 23
            LOCATE ICOUNTER+1,1,1,1,1
            PRINT " "+SKEYSTOINSERTDESCRIPTION(ICOUNTER)+"  "+SKEYSTOINSERTDESCRIPTION(ICOUNTER+13);
        NEXT ICOUNTER
    
        LOCATE 25,2,1,1,1
        PRINT "Abbr Descriptions. * means implanted return. Press alphanumeric, esc or enter.";
        LOCATE 1,1,1,1,1
    
    INPUTANOTHERKEY:
    REM USING SPARMFILE AND ICOUNTER VARIABLE THAT SHOULD BE EMPTY AND USABLE TO SAVE ON VARIABLE MEMORY SPACE
        INPUTVARIABLE=0&
        SPARMFILE=""
        ICOUNTER=0&
        LOCATE 24,49,1,1,1
        WHILE 2=2
           WHILE NOT INSTAT
           WEND
           SPARMFILE=INKEY$
           IF LEN(SPARMFILE)<>1 THEN ITERATE
           IF ASC(SPARMFILE)=27 THEN INPUTVARIABLE=0&:GOTO EXITINPUT
           IF ASC(SPARMFILE)=13 THEN INPUTVARIABLE=0&:GOTO EXITINPUT
           IF INSTR(SVALIDKEYINPUT,UCASE$(SPARMFILE)) THEN
               ICOUNTER=INSTR("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",UCASE$(SPARMFILE))
               IF ICOUNTER THEN INPUTVARIABLE=ICOUNTER:GOTO EXITINPUT
           END IF
        WEND
    EXITINPUT:
       SBUFFER = STRPTR32( SFULLSCREEN )
       FOR ICOUNTER = 0 TO 3999
           Video( ICOUNTER )=@SBUFFER
           INCR SBUFFER
       NEXT ICOUNTER
      LOCATE CSRLINEX,CURLINEY,1,1,1
       IF INPUTVARIABLE THEN
          POPUP STUFF SKEYSTOINSERT(INPUTVARIABLE),1,0
       END IF
    
    GOTO ENTERSLEEPSTATE
    DONOTDISPLAY:
      IF IPRINTDEVICE=0 THEN GOTO ENTERSLEEPSTATE
      IF LEN(SPRINTDEVICE)=0% THEN GOTO ENTERSLEEPSTATE
    
    REM READ THE FULL SCREEN
      SBUFFER = STRPTR32( SFULLSCREEN )
        FOR ICOUNTER = 0& TO 3999&
            @SBUFFER = Video( ICOUNTER )
            INCR SBUFFER
        NEXT ICOUNTER
    
    'CLEAR THE SCREEN
         FOR ICOUNTER = 0 TO 3999
          Video( ICOUNTER )=32
          INCR ICOUNTER
          Video( ICOUNTER )=07
        NEXT ICOUNTER
    REM USING SPARMFILE VARIABLE THAT SHOULD BE EMPTY AND USABLE TO SAVE ON VARIABLE MEMORY SPACE
        SPARMFILE=""
        LOCATE 15,3,1,1,1
        PRINT "Do you want to print the screen to port "+SPRINTDEVICE+": (Y N A or escape)";
        LOCATE 15,67,1,1,1
         WHILE 2=2
            WHILE NOT INSTAT:WEND
            SPARMFILE=INKEY$
            IF LEN(SPARMFILE)<>1 THEN ITERATE
            IF ASC(SPARMFILE)=27 THEN PRINT "escaped";:GOTO EXITINPUTB
            IF UCASE$(SPARMFILE)="Y" THEN PRINT SPARMFILE;:GOTO PRINTTHESCREEN
            IF UCASE$(SPARMFILE)="N" THEN PRINT SPARMFILE;:GOTO EXITINPUTB
            IF UCASE$(SPARMFILE)="A" THEN PRINT SPARMFILE;:GOTO EXITINPUTB
         WEND
    
    
    
    PRINTTHESCREEN:
        LOCATE 16,3,1,0,0
        PRINT "Printing to printer port "+SPRINTDEVICE+":";
       $EVENT ON
        ERRCLEAR
        ON ERROR GOTO PRINTERROR
        OPEN SPRINTDEVICE FOR OUTPUT AS #1                                    
        ON ERROR GOTO 0
        FOR ICOUNTER=1& TO 25&                                                    
            ICR=(ICOUNTER*80%)-79%                                                     
            PRINT #1,USING "&";MID$(SSCREENTEXT,ICR,80%)                                              
        NEXT I%                                                           
        PRINT #1,USING "&";CHR$(12%);                                      
        CLOSE 1                                                           
        LOCATE 17,3,1,0,0
        PRINT "Printed";
        ERRCLEAR
        $EVENT OFF
        GOTO EXITINPUTB
    
    PRINTERROR:
        RESUME PRINTERROR1
        ERRCLEAR
    PRINTERROR1:
    $EVENT OFF
        LOCATE 18,3,1,0,0
        PRINT "Print error: could not print to "+SPRINTDEVICE+":";
        LOCATE 19,3,1,0,0
        PRINT "Press a key to continue.";
    
        WHILE 2=2
          WHILE NOT INSTAT:WEND
          SPARMFILE=INKEY$
          IF LEN(SPARMFILE)>1 THEN ITERATE
          GOTO EXITINPUTB
        WEND
    
    
    EXITINPUTB:
       SBUFFER = STRPTR32( SFULLSCREEN )
       FOR ICOUNTER = 0 TO 3999
           Video( ICOUNTER )=@SBUFFER
           INCR SBUFFER
       NEXT ICOUNTER
       LOCATE CSRLINEX,CURLINEY,1,1,1
    
    
    
    
    ENTERSLEEPSTATE:
      POPUP SLEEP 'going to sleep
    
    WEND
    STOP
    END
    
    SUB READPARMETERFILE
      DIM ILOCATION AS INTEGER
      DIM IARRAYITEM AS INTEGER
      DIM SFILELINE AS STRING
      DIM SSHORTDESCRIPTION AS STRING
      DIM SQUICKKEYTOPRESS AS STRING
      DIM SFULLSHORTDESCRIPTION AS STRING
      OPEN SPARMFILE FOR INPUT AS #1
      WHILE NOT EOF(1)
         LINE INPUT #1,SFILELINE
         SFILELINE=TRIM$(SFILELINE)
         IF LEN(SFILELINE)<2% THEN ITERATE
         IARRAYITEM=INSTR("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",UCASE$(LEFT$(SFILELINE,1)))
         IF IARRAYITEM=0% THEN ITERATE
         SQUICKKEYTOPRESS=MID$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",IARRAYITEM,1%)
         SFILELINE=TRIM$(RIGHT$(SFILELINE,LEN(SFILELINE)-1%))
         IF LEN(SFILELINE)=0% THEN ITERATE
         ICR=0%
         IF INSTR(SFILELINE,"..") THEN
               IF RIGHT$(SFILELINE,2)=".." THEN ICR=1%
         END IF
         IF ICR THEN
             WHILE RIGHT$(SFILELINE,2)=".."
             SFILELINE=LEFT$(SFILELINE,LEN(SFILELINE)-1)
             WEND
         END IF
         SFILELINE=SFILELINE+" "
         ILOCATION=INSTR(SFILELINE,".")
         IF ILOCATION THEN
            SSHORTDESCRIPTION=LEFT$(SFILELINE,ILOCATION-1)
            SFILELINE= TRIM$(  RIGHT$(SFILELINE,LEN(SFILELINE)-ILOCATION))
            ELSE
            SSHORTDESCRIPTION=TRIM$(SFILELINE)
         END IF
         SFULLSHORTDESCRIPTION=SSHORTDESCRIPTION
         IF LEN(SSHORTDESCRIPTION)=0% THEN ICR=0%
         IF LEN(SSHORTDESCRIPTION)>35% THEN
            SSHORTDESCRIPTION=LEFT$(SSHORTDESCRIPTION,35)
            ELSE
            SSHORTDESCRIPTION=LEFT$(SSHORTDESCRIPTION+STRING$(35," "),35)
         END IF
    
         IF ICR THEN
            ICARRIAGERETURNWANTED(IARRAYITEM)=ICR
            SKEYSTOINSERTDESCRIPTION(IARRAYITEM)=SQUICKKEYTOPRESS+"* "+SSHORTDESCRIPTION
            ELSE
            SKEYSTOINSERTDESCRIPTION(IARRAYITEM)=SQUICKKEYTOPRESS+"- "+SSHORTDESCRIPTION
         END IF
         IF LEN(SFILELINE) THEN
            SKEYSTOINSERT(IARRAYITEM)=SFILELINE
            ELSE
            SKEYSTOINSERT(IARRAYITEM)=TRIM$(SFULLSHORTDESCRIPTION)
         END IF
         IF ICR AND LEN(SKEYSTOINSERT(IARRAYITEM)) THEN SKEYSTOINSERT(IARRAYITEM)=SKEYSTOINSERT(IARRAYITEM)+CHR$(13)
         IF LEN(SKEYSTOINSERT(IARRAYITEM))>256 THEN SKEYSTOINSERT(IARRAYITEM)=LEFT$(SKEYSTOINSERT(IARRAYITEM),256)
      SFILELINE=""
      SSHORTDESCRIPTION=""
      SFULLSHORTDESCRIPTION=""
      SQUICKKEYTOPRESS=""
      WEND
      CLOSE #1
      SFILELINE=""
      SSHORTDESCRIPTION=""
      SQUICKKEYTOPRESS=""
      SFULLSHORTDESCRIPTION=""
    
      REM USING  VARIABLE ICR AS A COUNTER
             SVALIDKEYINPUT=""  
             FOR ICR=1 TO 36
                 SKEYSTOINSERTDESCRIPTION(ICR)=TRIM$(SKEYSTOINSERTDESCRIPTION(ICR))
                 IF LEN(SKEYSTOINSERTDESCRIPTION(ICR)) THEN
                     SVALIDKEYINPUT=SVALIDKEYINPUT+UCASE$(LEFT$(SKEYSTOINSERTDESCRIPTION(ICR),1))
                 END IF
                 IF LEN(SKEYSTOINSERTDESCRIPTION(ICR))<>38& THEN
                      SKEYSTOINSERTDESCRIPTION(ICR)=LEFT$(SKEYSTOINSERTDESCRIPTION(ICR)+SPACE$(38),38)
                 END IF
             NEXT ICR
       ICONFIGFILEREAD=1&
    END SUB
    Code:
    #
    #   This file is the configuration file for the TSRXNOTE program
    #   This file is used by tsrXnote tsr program to configure hot keys 0-9 and a-z
    #   These settings only are active when F12 is pressed while in the
    #  
    #   Start with a number or letter to make the hot keys for the program.
    #   If you leave out a number or letter, then it will be simply disabled
    #   There should be not carriage returns in a single line.
    #   Each line to configure has 2 parts.
    #   The first part of the line up to 35 characters is a short description up to the first period.
    #   The second part is what is placed in the memo screen up to 256 characters.
    #   You should be able to have mutiple sentences after the first sentence.
    #   You can insert and automatic carriage return by ending the second part
    #     of the line with two consecutive dots ".."
    #  The first number or letter in a line here indicates the hot key.
    #  The last number or letter found is what is used in the case there is dupplication of a number or letter.
    #  you leave out a number or letter or use a # character to disable it.
    #  Again, placing double dots at the end of the line of the last sentence will cause
    #    the hot key to enter a carriage return after the message is placed in the memo section of
    #    the finance program. You will see and asterick by the hot key to indicate there is a carriage return at the
    #    end and the carriage return will be inserted automatically in the finance program memo area.
    #
    #
    #   IF you put LPT1 TO LPT3 on the command  line. You can print the screen.
    
    
    
    0 Type 0 in. Inserted notation XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0..
    1 Type 1 in. Inserted notation 1.
    2 type 2 in. Inserted notation 2.
    3 type 3 in. Inserted notation 3.
    4 type 4 in. Inserted notation 4.
    5 type 5 in. Inserted notation 5.
    6 type 6 in. Inserted notation 6.
    7 type 7 in. Inserted notation 7.
    8 type 8 in. Inserted notation 8.
    9 type 9 in. Inserted notation 9.
    a type a in. Inserted notation a.
    b type b in. Inserted notation b.
    c type c in. Inserted notation c.
    d type d in. Inserted notation d.
    e type e in. Inserted notation e.
    f type f in. Inserted notation f.
    g type g in. Inserted notation g.
    h type h in. Inserted notation h.
    i type i in. Inserted notation i.
    j type j in. Inserted notation j.
    k type l in. Inserted notation k.
    l type l in. Inserted notation l.
    m type m in. Inserted notation m.
    n type n in. Inserted notation n.
    o type o in. Inserted notation o.
    p type p in. Inserted notation p.
    q type q in. Inserted notation q.
    r type r in. Inserted notation r.
    s type s in. Inserted notation s.
    t type t in. Inserted notation t.
    u type u in. Inserted notation u.
    v type v in. Inserted notation v.
    w type w in. Inserted notation w.
    x type x in. Inserted notation x.
    y type y in. Inserted notation y.
    z type z in. Inserted notation z.
    
    
    #   END OF FILE    this line is not needed but a last line other that a data kind of line is kind of a good thing
    #   END OF FILE
    Attached Files
    p purvis
Working...
X