Hi all,
I'm looking for a function like the visual basic SendKey in order to send some Keys to a window process.
Do you know something like this ?
In alternative, do you know a way to put the focus on a Windows process ?
Thank you in advance
Function TesteSend()
MySendText("TESTANDO")
Return
Static Function MySendText(cTexto)
Local nI
Local cCar
Local lShift
// sem shift
cTexto := StrTran(cTexto,".",Chr(190))
cTexto := StrTran(cTexto,"/",Chr(193))
cTexto := StrTran(cTexto,"=",Chr(187))
// com shift
cTexto := StrTran(cTexto,":",Chr(191))
If GetKeyToggle(20) // se capslock estiver ativo
MySendKey(20,0)
MySendKey(20,45)
EndIf
If Len(cTexto)==0
MySendKey(17,0) // control
MySendKey(Asc(Upper("V")),0)
MySendKey(Asc(Upper("V")),45)
MySendKey(17,45)
Return
EndIf
For nI := 1 to Len(cTexto)
cCar := SubStr(cTexto,nI,1)
lShift := IsUpper( cCar )
If lShift
MySendKey(16,0)
EndIf
MySendKey(Asc(Upper(cCar)),0)
If lShift
MySendKey(16,45)
EndIf
Next
Return
#pragma begindump
#include <windows.h>
#include <stdlib.h>
#include "hbapi.h"
#define WH_KEYBOARD_LL 13
HB_FUNC ( EMTGETWINDOW ) // RETORNA A WINDOW QUE ESTA EM FOCO
{
hb_retni(GetForegroundWindow());
}
HB_FUNC( MYSENDKEY )
{
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
#include "FiveWin.ch"
#define GW_CHILD 5
#define GW_HWNDNEXT 2
FUNCTION Main()
LOCAL oWnd, hWnd, hCtrl, cClassName, cTitle
cTitle := PADR("TEST", 200)
IF MsgGet( "Please write the title of a window", "Title:", @cTitle)
hWnd := FindWindow( 0, ALLTRIM(cTitle))
IF hWnd <= 0
MsgInfo( "Sorry I can't find that window" )
ELSE
hCtrl := GetWindow( hWnd, GW_CHILD )
WHILE hCtrl != 0
cClassName := Upper(GetClassName(hCtrl))
IF cClassName = "EDIT"
? cClassName+" "+GetWindowText(hCtrl)
ENDIF
hCtrl = GetWindow( hCtrl, GW_HWNDNEXT )
END
ENDIF
ENDIF
RETURN NIL
function Main()
local hWnd
hWnd:=FindWindow(0,"Noname - Notepad")
SetForegroundWindowForce(hWnd)
__keyboard("a")
return
STATIC FUNCTION SetForegroundWindowForce(hWnd)
SetFocus(hWnd)
SendKey(VK_RETURN) // The key
SetFocus(hWnd)
SetForegroundWindow(hWnd)
SysRefresh()
RETURN NIL
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 36 guests