; 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