> how to support from windows xp/7 ?!
#include '
inkey.ch'
#define NOTEPAD
Proc Main()
Local cTitle, cControl, nKey, lSender, lSucc
#ifdef NOTEPAD
__run('start notepad')
cTitle := 'Untitled - Notepad'
cControl := 'Edit'
lSender := .t.
#else
//make copy of program.exe to program0.exe
cTitle := hb_Argv(0)
cTitle := SubStr(cTitle, Rat('\', cTitle) +1)
cTitle := Left(cTitle, At('.', cTitle) -1)
lSender := Right(cTitle, 1) # '0'
cTitle := if(lSender, cTitle +'0', Left(cTitle, Len(cTitle) -1))
#endif
if lSender
? 'Sending to "' +if(cTitle == Nil, 'ourselves', cTitle) +'"...'
else
? 'Waiting from "' +cTitle +'"...'
endif
While (nKey := INKEY(0)) # K_ESC
? if(lSender, 'send', 'receive') +if(nKey < 32, ' <' +Ltrim(Str(nKey)) +'>', ' "' +Chr(nKey) +'"')
if lSender
if nKey > 48 .and. nKey < 54 //keys 1..5
lSucc := SendKeys({'one', 'two', 'three', 'four', 'five'}[nKey -48], cTitle, cControl)
else
lSucc := SendKeys(nKey, cTitle, cControl)
endif
if !lSucc
?? ' --- no receiver!'
endif
endif
end
Return
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
HB_FUNC( SENDKEYS )
{
HANDLE WndHandle = ISCHAR(2) ? FindWindow( NULL, hb_parc( 2 ) ) : GetForegroundWindow();
BOOL bSuccess = FALSE;
if( WndHandle )
{
if( ISCHAR(3) )
WndHandle = FindWindowEx( WndHandle, 0, hb_parc( 3 ), NULL );
if( WndHandle )
{
if( ISNUM(1) )
SendMessage( WndHandle, WM_CHAR, hb_parni( 1 ), 1 );
else
{
const char *pStr = hb_parc( 1 );
size_t sPos, sLen = hb_parclen( 1 );
for( sPos = 0; sPos < sLen; sPos++ )
SendMessage( WndHandle, WM_CHAR, pStr[sPos], 1 );
}
bSuccess = TRUE;
}
}
hb_retl( bSuccess );
}
#pragma ENDDUMP
Best regards,
Saulius