Page 1 of 1

Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 2:12 pm
by emotta_no
Antonio, the funcion "SenKey" is with bug... I developed a new function SendKey. Please, see it.


Code: Select all | Expand


#include "fivewin.ch"

Function TestSendKey()
Local nKey
Local oWnd
Private oTimer,oTimer2

   DEFINE WINDOW oWnd TITLE "3D objects"


   ACTIVATE WINDOW oWnd On Init (MyHook(oWnd))

Return

Static Function MyHook(oWnd)

DEFINE TIMER oTimer OF oWnd INTERVAL 100 ACTION Processar_Tecla()
oTimer:Activate()


Return

Static Function Processar_Tecla()
ThreadSleep(3000) // wait for open notepad
MySendText("Hello World")
Return




// functions SENDKEY


Static Function MySendKey(nTecla)
FWSendKey(nTecla,0) // press key
FWSendKey(nTecla,1) // unpress key
Return

Static Function MySendText(cTexto)
Local nI
Local cCar
Local lShift

For nI := 1 to Len(cTexto)
   cCar := SubStr(cTexto,nI,1)
   lShift := IsUpper( cCar )
   If lShift
      FWSendKey(16,0)  // press shift key
   EndIf
   MySendKey(Asc(Upper(cCar)),0)
   If lShift
      FWSendKey(16,45) // unpress shift key
   EndIf
Next

Return



*##################################################################################################
* FUNCIONES EN C    
*##################################################################################################

#pragma begindump

#include <windows.h>
#include <stdlib.h>
#include "hbapi.h"


HB_FUNC( FWSENDKEY )
{
int nPress;

nPress = hb_parni(2);

if (nPress == 0)
   keybd_event( hb_parni(1), nPress, KEYEVENTF_EXTENDEDKEY | 0, 0 );
else
   keybd_event( hb_parni(1), nPress, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );

}

#pragma enddump

 

Re: Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 7:07 pm
by Horizon
Thank you emotta_no,

It worked for me.

How Can I send Tab key?

Re: Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 7:09 pm
by emotta_no
Yes, you can...

MySendKey(VK_TAB)

Re: Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 10:03 pm
by Antonio Linares
Eduardo,

I have included it this way for the next FWH version, Thanks! :-)

Code: Select all | Expand

HB_FUNC( FW_SENDKEY )
{
   if( hb_parni( 2 ) == 0 )
      keybd_event( ( BYTE ) hb_parni( 1 ), ( BYTE ) hb_parni( 2 ),
                   KEYEVENTF_EXTENDEDKEY | 0, 0 );
   else
      keybd_event( ( BYTE ) hb_parni( 1 ), ( BYTE ) hb_parni( 2 ),
                   KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );
}

Re: Crash/GPF in SendKey Functon

Posted: Thu Jul 24, 2014 2:23 pm
by emotta_no
Great,