; FILEWEDG ; ; Program for Proteus ; ; (C) 2005 Simone Zanella Productions ; ; Emulates keyboard (wedge emulation) by entering data coming from a file. ; 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: ; - POLLDELAY = polling interval to check for the file ; - KILLFILE = delete file after transmission (flag); if 0, file is not deleted, but is not ; transmitted again until size, date or time change ; - PATHNAME = file to be sent ; - POSTFIX = terminator (usually: "{ENTER}") ; ; In detail, the program does the following: ; - check if the specified file is available; ; - if so, 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 !include "win32.prt" CONST POLLDELAY = 3000 CONST KILLFILE = 0 CONST PATHNAME = "C:\\DATA.TXT" CONST POSTFIX = "{ENTER}" LASTSIZE = "" LASTDATE = "" LASTTIME = "" WHILE 1 IF KILLFILE H = FOPEN(PATHNAME, 4) ELSE ; Check size, date and time and send the file only when changed HD = DIROPEN(PATHNAME, 1) IF NEQ(HD, -1) IF OR(STRNEQ(LASTSIZE, DIRLAST(HD, 2)), \ STRNEQ(LASTDATE, DIRLAST(HD, 3)), \ STRNEQ(LASTTIME, DIRLAST(HD, 4))) H = FOPEN(PATHNAME, 4) IF NEQ(H, -1) DIRCLOSE(HD) HD = DIROPEN(PATHNAME, 1) LASTSIZE = DIRLAST(HD, 2) LASTDATE = DIRLAST(HD, 3) LASTTIME = DIRLAST(HD, 4) FI ELSE H = -1 FI DIRCLOSE(HD) ELSE H = -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 NEQ(H, -1) 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) IF KILLFILE FREMOVE(PATHNAME) FI 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