INCLUDE "SYSTEM.OXH" INCLUDE "CONST.OPH" PROC Start: LOCAL ThreadID&,Ret&,Prev&,Choice% dINIT "SendKeyEventToApp&: demonstration (with Word)" dCHOICE Choice%,"Send","Ctrl-P,Ctrl-Shift-F,s,S" dBUTTONS "OK",13+$300,"Cancel",27+$300 IF DIALOG=0 STOP ENDIF ThreadID&=GetThreadIdFromAppUID&:(&1000007F,prev&) REM This is UID of Word (as an example) REM You MUST have a Word session open for this to work Ret&=SetForegroundByThread&:(ThreadID&,&0) PAUSE 2 : REM wait to allow app to come to foreground VECTOR Choice% CtrlP,CtrlShiftF,LowerS,UpperS ENDV CtrlP:: REM This sends Ctrl-P to Word REM In OPL, if you are using a Ctrl modifier, the keycode REM is specified as the number of the letter in the alphabet REM i.e. a=1,b=2,c=3 ... etc. - 16 is p Ret&=SendKeyEventToApp&:(ThreadID&,&0,16,KModifierCtrl&,KModifierCtrl&,&0) GOTO Skip:: REM Normal keys are sent by specifying ASCII keycode REM and appropriate non-control modifier LowerS:: REM This sends a lowercase s Ret&=SendKeyEventToApp&:(ThreadID&,&0,ASC("s"),&0,&0,&0) GOTO Skip:: UpperS:: REM This sends a capital S Ret&=SendKeyEventToApp&:(ThreadID&,&0,ASC("S"),&0,&0,&0) GOTO Skip:: CtrlShiftF:: REM The "Shift" modifier really only applies when combined REM with other modifiers - font dialog in Word - Ctrl+Shift+F Ret&=SendKeyEventToApp&:(ThreadID&,&0,6,KModifierShift&+KModifierCtrl&,KModifierShift&+KModifierCtrl&,&0) GOTO Skip:: Skip:: REM Go back to start Start: ENDP