FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Crash/GPF in SendKey Functon
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM

Crash/GPF in SendKey Functon

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


Code (fw): Select all Collapse
#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
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM

Re: Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 07:07 PM

Thank you emotta_no,

It worked for me.

How Can I send Tab key?

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM

Re: Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 07:09 PM

Yes, you can...

MySendKey(VK_TAB)

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Crash/GPF in SendKey Functon

Posted: Wed Jul 23, 2014 10:03 PM
Eduardo,

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

Code (fw): Select all Collapse
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
Posts: 33
Joined: Thu Jul 04, 2013 09:28 PM

Re: Crash/GPF in SendKey Functon

Posted: Thu Jul 24, 2014 02:23 PM

Great,

Continue the discussion