Sendkey Function randomly working

Startbeitrag von Gautam.pcs.crosspost am 04.08.2009 07:51

Greetings forum users

I am trying to send keystrokes to a windows application using the Sendkey command. The command is behaving strangely - sometimes working correctly, sometimes only sending part of the string and at times not sending any keystrokes at all. I am using Windows XP and Windev 14.

The code of the app is given below:

***************************************************************

Procedure SendInput(nWinHandle, sSendString)

//nWinHandle receives a Windows Handle of the third party app (of type system int) and sSendString contains the string to send to the third party app.

bRes is boolean = False //Receives the result of the Sendkey function

If SysValidHandle(nWinHandle) then //check if windows handle is valid
SysWinActive(nWinHandle) //Give focus to the Win App that receives the input
Multitask(50)
bRes = Sendkey(sSendString, nWindHandle)
If bRes = False then
Error("Could not send string")
End
Else
Error("Windows Handle is invalid!")
End

***************************************

Notes:
1. None of the error messages are triggered.
2. If for example sSendString contains the word "Test-App" then sometimes the windows application receives
a. Test-App (correct)
b. est-App(first letter missing - Incorrect)
c. -App(several letters missing - Incorrect)
d. "" (blank nothing is sent) - but the bRes flag returns TRUE

3. Window handle received is valid and does not trigger an error.

I have researched a bit on the net but could not find anything that has similar behaviour as above.

I would appreciate any help - or perhaps alternate way of sending keystrokes to a Windows Application.

Thanks and regards

Gautam

Message forwarded from pcsoft.us.windev

Antworten:

Hi Gautam,

Try the multitask delay a bit longer and/or a negative value.

Regards,
Piet

von Piet van Zanten - am 04.08.2009 08:06
Hello Gautam,

Perhaps you can use PostMessage or SendMessage.

HTH.

von Louis Verbraak - am 04.08.2009 09:09
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.