Crash/GPF in SendKey Functon

Post Reply
emotta_no
Posts: 33
Joined: Thu Jul 04, 2013 9:28 pm

Crash/GPF in SendKey Functon

Post 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

 
Horizon
Posts: 1329
Joined: Fri May 23, 2008 1:33 pm
Has thanked: 6 times
Been thanked: 1 time

Re: Crash/GPF in SendKey Functon

Post by Horizon »

Thank you emotta_no,

It worked for me.

How Can I send Tab key?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
emotta_no
Posts: 33
Joined: Thu Jul 04, 2013 9:28 pm

Re: Crash/GPF in SendKey Functon

Post by emotta_no »

Yes, you can...

MySendKey(VK_TAB)
User avatar
Antonio Linares
Site Admin
Posts: 42652
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 67 times
Been thanked: 94 times
Contact:

Re: Crash/GPF in SendKey Functon

Post 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 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
emotta_no
Posts: 33
Joined: Thu Jul 04, 2013 9:28 pm

Re: Crash/GPF in SendKey Functon

Post by emotta_no »

Great,
Post Reply