Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a Send Key Function
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00145446
Message ID:
00145525
Views:
36
Hi Bret,

>We need one to send keystrokes to another non-visual foxpro window based on a window title.

This is a CompuServe message from Markus Auer that deals with this topic. Maybe it gives you some ideas.

*-----------------------------------------------------------------------------
I've done this keystroke-sending. You have to play around a little bit with it, but it works. I'll send you a copy'n paste of the code I use:

Greetings from Salzburg Austria, Markus


*** Looking, if the program is running already
declare keybd_event in win32api short,long,long
declare integer PostMessage in win32api long,long,long,long
declare short FindWindow in WIN32API string class, string window
declare short ShowWindow in WIN32API short whnd, short mode
declare integer GetWindow in win32api integer whnd, integer cmd
declare integer GetTopWindow in win32api integer
declare integer GetWindowText in win32api ;
integer hwnd, string @lc, integer lcsize
DECLARE INTEGER GetProfileString IN Win32API ;
String cSection, String cKey, String cDefault, ;
String @cBuffer, Integer nBufferSize

lc=space(256)
lnh=gettopwindow(0)
do while lnh>0
ln=getwindowtext(lnh,@lc,255)
if ln>=20
if left(lc,20)='NetSentinel-C Editor'
exit
endif
endif
lnh=getwindow(lnh,2)
enddo
if lnh<=0 && program isn't running
lc=sys(16)
lc=subst(lc,rat(' ',lc)+1)
lc=left(lc,rat('\',lc))+'w32edito.exe'
if file(lc)
run /N7 &lc.
lnh=findwindow(.null.,'NetSentinel-C Editor')
endif
endif
if lnh<=0
=messagebox('Program not found!',48,'Warnung')
return .F.
endif
showwindow(lnh,0)
showwindow(lnh,1)
inkey(0.1)

** Keystroke ALT+F and R
postmessage(lnh,262,asc('f'),bitset(0,29)) && Reset
postmessage(lnh,258,asc('r'),0)
** Keystroke ALT+S and P
postmessage(lnh,262,asc('s'),bitset(0,29)) && Passwords
postmessage(lnh,258,asc('p'),0)

** waiting until the needed dialog is opened
lndlg=0
do while lndlg=0
lndlg=findwindow(.null.,'Password Entry')
enddo

lcd1='BlaBlaBla'
lcd2='BlaBlaBla'
ll=!empty(lcd1) and !empty(lcd2)
for ln=1 to len(lcd1)
lc=subst(lcd1,ln,1)
if isupper(lc)
=keybd_event(16,0,0)
=keybd_event(asc(lc),0,0)
=keybd_event(asc(lc),0,2)
=keybd_event(16,0,2)
else
=keybd_event(asc(upper(lc)),0,0)
=keybd_event(asc(upper(lc)),0,2)
endif
endfor
=keybd_event(9,0,0)
for ln=1 to len(lcd2)
lc=subst(lcd2,ln,1)
if isupper(lc)
=keybd_event(16,0,0)
=keybd_event(asc(lc),0,0)
=keybd_event(asc(lc),0,2)
=keybd_event(16,0,2)
else
=keybd_event(asc(upper(lc)),0,0)
=keybd_event(asc(upper(lc)),0,2)
endif
endfor
=keybd_event(13,0,0)
postmessage(lnh,262,asc('f'),bitset(0,29)) && Reset
postmessage(lnh,258,asc('n'),0)
inkey(0.1)
postmessage(lnh,262,asc('v'),bitset(0,29)) && Decimal
postmessage(lnh,258,asc('h'),0)
inkey(0.1)
for ln=1 to 120
lc=right(transform(asc(subst(lcdata,ln,1)),'@0'),2)+chr(13)
do while len(lc)>0
postmessage(lnh,258,asc(lc),0)
lc=subst(lc,2)
enddo
endfor
postmessage(lnh,262,asc('k'),bitset(0,29)) && Write
postmessage(lnh,258,asc('w'),0)
return

Christof
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform