; ACTSYNC
;
; Program for Proteus
;
; (C) 2005 Simone Zanella Productions
;
; Emulates keyboard (wedge emulation) by entering data coming from a file on a device connected
; through ActiveSync.
; This program can be installed as a script for Proteus Service.
;
; The parameters can be found at the very beginning of the program; the meaning is as follow:
; - TIMEOUT = timeout (in ms) for device answer
; - KILLFILE = delete file after transmission (flag); if 0, file is not deleted, but is not
;   transmitted again until size, date or time change
; - TEMPFILE = name of a temporary file, where data are temporarily downloaded before being stuffed in the
;   keyboard buffer
; - FILENAME = name of the file on the terminal
; - POSTFIX = terminator (usually: "{ENTER}")
;
; In detail, the program does the following:
; - check if the device and the specified file are available;
; - if so, download the file into a temporary file and send it one line at a time (followed by POSTFIX);
; - delete file (if KILLFILE is not 0) or check size, date and time and re-send the file
;   only when one of these properties change.
;
; The lines below (commented out) allow for alternate behaviours:
; - bring to the foreground a specific window (Ultra-Edit) and emulate keyboard;
; - open notepad (if it is not running), emulate keyboard and return to previous window.

#!proteus -z -j

!extern CEGetFile, PROTEXT.DLL, ProteusCEGetFile, 4, 0
!extern CEFileInfo, PROTEXT.DLL, ProteusCEFileInfo, 2, 560

!include "win32.prt"

CONST TIMEOUT = 3000
CONST KILLFILE = 0
CONST TEMPFILE = "C:\\ACTSYNC.TMP"
CONST FILENAME = "/My Documents/dati.txt"
CONST POSTFIX = "{ENTER}"

LASTCEFIND = ""
WHILE 1
  ; Remove temporary file
  FREMOVE(TEMPFILE)

  IF KILLFILE
    ; If file is to be removed after transmission, download it directly
    RESULT = CEGetFile(FILENAME, TEMPFILE, TIMEOUT, KILLFILE)

  ELSE  

    ; Check date/time/size and download the file only when one of these parameters has changed
    CEFIND = CEFileInfo(FILENAME, TIMEOUT)

    ; If it is not a service and the user pressed ESC then exit
    !ifndef SERVICE
      IF KBDHIT()
        IF EQ(GETCH(), 27)
          BREAK
        FI
      FI
    !endif
        
    IF ISNOTEMPTY(CEFIND)
      IF STRNEQ(LEFT(CEFIND, 304), LEFT(LASTCEFIND, 304))
        RESULT = CEGetFile(FILENAME, TEMPFILE, TIMEOUT, KILLFILE)
        IF EQ(RESULT, 0)
          CEFIND = CEFileInfo(FILENAME, TIMEOUT)
          IF ISNOTEMPTY(CEFIND)
            LASTCEFIND = CEFIND
          FI
        FI
      ELSE     
        RESULT = -1
      FI
    ELSE
      RESULT = -1
    FI   
  FI

  ; If it is not a service and the user pressed ESC then exit
  !ifndef SERVICE
    IF KBDHIT()
      IF EQ(GETCH(), 27)
        BREAK
      FI
    FI
  !endif 

  IF EQ(RESULT, 0)
    H = FOPEN(TEMPFILE, 1)
    IF EQ(H, -1)
      CONTINUE
    FI
    
    WHILE NOT(FEOF(H))
      Dato1 = FREADLN(H)
      
      ; >>> Additional code commented out (alternate behaviour) <<<
      ;
      ; Bring to the foreground a specific window (which is known to exist) before
      ; emulating keyboard.
      ;
      ; IF STRLEN(Dato1)
      ;   W32SETFOCUS(W32FINDWINDOW("*ULTRAEDIT-32*"))
      ;   W32SENDKEYS(KTrans(Dato1) "{ENTER}")
      ; FI
      ; CONTINUE
  
      ; >>> Additional code commented out (alternate behaviour) <<<
      ;
      ; Select Notepad window; if it does not exist, run the program, wait 2 seconds, then
      ; emulate keyboard. Focus is returned to the window which had it before selecting Notepad window.
      ;
      ; IF STRLEN(Dato1)
      ;   Hold = W32GETFOCUS()
      ;     
      ;   HW = W32FINDWINDOW("*Notepad*")
      ;   IF EQ(HW, 0)
      ;     W32SHELL("NOTEPAD.EXE")
      ;     SLEEP(2)
      ;     HW = W32FINDWINDOW("*Notepad*")
      ;   FI
      ;   IF NEQ(HW, 0)
      ;     W32SETFOCUS(HW)
      ;     W32SENDKEYS(KTrans(Dato1))
      ;   ELSE
      ;     CONSOLELN "Notepad could not be opened!"
      ;   FI
      ;   W32SETFOCUS(Hold)
      ; FI
      ; CONTINUE
    
      W32SENDKEYS(KTrans(Dato1) POSTFIX)
    LOOP      
    FCLOSE(H)
  FI
LOOP
ABORT 0   


FUNCTION KTrans(s)

; Special characters: characters which are not available on the keyboard
; require special treatment (Alt + 3 digits) - useful for foreign keyboards

l = STRLEN(s)
r = ""
FOR x = 1 TO l
  c = SUBSTR(s, x, 1)
  SWITCH c STREQ
  ON "~"
    r = r "{ALT DOWN}{NUMPAD1}{NUMPAD2}{NUMPAD6}{ALT UP}"
  ON "{"
    r = r "{ALT DOWN}{NUMPAD1}{NUMPAD2}{NUMPAD3}{ALT UP}"    
  ON "}"
    r = r "{ALT DOWN}{NUMPAD1}{NUMPAD2}{NUMPAD5}{ALT UP}"
  ON "+", "^", "%", "(", ")", "[", "]"
    r = r "{" c "}"
  OTHER
    r = r c
  OFF
NEXT
RETURN r
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell