Equivalent of VB Sendkey
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Equivalent of VB Sendkey
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
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
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Equivalent of VB Sendkey
If you search the forum for "sendkey" you will find a number of postings. Perhaps one of those will help.
- Rick Lipkin
- Posts: 2677
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
- Been thanked: 2 times
Re: Equivalent of VB Sendkey
Marco
Can you not use __KeyBoard() function ?? .. or possibly create a hidden button and put some code behind it and call it with oBtn:Click()
Rick Lipkin
Can you not use __KeyBoard() function ?? .. or possibly create a hidden button and put some code behind it and call it with oBtn:Click()
Rick Lipkin
Re: Equivalent of VB Sendkey
I made this function. It do this.
Code: Select all | Expand
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
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Equivalent of VB Sendkey
Thank you all for the suggests but my main issue is not to send the key due there are several way to do this,
my issue is to get the hwnd container.
Essentially, having the name of the process (example "winapp") I need to send some Keys to this app from my app,
like the user is using the winapp and it is pressing some Keys to be clear.
my issue is to get the hwnd container.
Essentially, having the name of the process (example "winapp") I need to send some Keys to this app from my app,
like the user is using the winapp and it is pressing some Keys to be clear.
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
- Antonio Linares
- Site Admin
- Posts: 42651
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 62 times
- Been thanked: 94 times
- Contact:
Re: Equivalent of VB Sendkey
Marco,
First of all you need to get the handle of the window where you are going to send the keys to.
You can get it from the caption of the main window of the app:
FindWindow( 0, "winapp" ) --> handle of the window
Now, once you have it you can send it any windows messages
First of all you need to get the handle of the window where you are going to send the keys to.
You can get it from the caption of the main window of the app:
FindWindow( 0, "winapp" ) --> handle of the window
Now, once you have it you can send it any windows messages

- Antonio Linares
- Site Admin
- Posts: 42651
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 62 times
- Been thanked: 94 times
- Contact:
Re: Equivalent of VB Sendkey
Marco,
If it is a control of "winapp", then you have to step through all its child controls until you find it:
Here you have an example looking for an "edit" child control:
If it is a control of "winapp", then you have to step through all its child controls until you find it:
Here you have an example looking for an "edit" child control:
Code: Select all | Expand
#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
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Equivalent of VB Sendkey
Hi Antonio,
thank for your suggest, FindWindow is fine for my case
I'm trying to send some chars to the opened Notepad from my FWH app,
Findwindow return the notepad hWnd but using __keyboard() notepad doesn't receive the chars despite it has focus.
Any ideas ? Do I have to replace __keyboard with another function in this case ?
Thank you.
------
function Main()
local hWnd
hWnd:=FindWindow(0,"Noname - Notepad")
SetFocus(hWnd)
__keyboard("a")
return
thank for your suggest, FindWindow is fine for my case
I'm trying to send some chars to the opened Notepad from my FWH app,
Findwindow return the notepad hWnd but using __keyboard() notepad doesn't receive the chars despite it has focus.
Any ideas ? Do I have to replace __keyboard with another function in this case ?
Thank you.
------
function Main()
local hWnd
hWnd:=FindWindow(0,"Noname - Notepad")
SetFocus(hWnd)
__keyboard("a")
return
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
- Antonio Linares
- Site Admin
- Posts: 42651
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 62 times
- Been thanked: 94 times
- Contact:
Re: Equivalent of VB Sendkey
Marco,
Use three underscores on the function name:
_ _ _keyboard( "Hello world" )
together
Use three underscores on the function name:
_ _ _keyboard( "Hello world" )
together

- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Equivalent of VB Sendkey
Nothing to do,
"Hello world" always go at the end of my fwh app on the Windows cmd prompt instead of notepad.
It seems like notepad doesn't receive the focus before I use ___keyboard
"Hello world" always go at the end of my fwh app on the Windows cmd prompt instead of notepad.
It seems like notepad doesn't receive the focus before I use ___keyboard
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
Re: Equivalent of VB Sendkey
Marco,
Try so:
Regards
Try so:
Code: Select all | Expand
function Main()
local hWnd
hWnd:=FindWindow(0,"Noname - Notepad")
SetForegroundWindowForce(hWnd)
__keyboard("a")
return
Code: Select all | Expand
STATIC FUNCTION SetForegroundWindowForce(hWnd)
SetFocus(hWnd)
SendKey(VK_RETURN) // The key
SetFocus(hWnd)
SetForegroundWindow(hWnd)
SysRefresh()
RETURN NIL
Regards
- Antonio Linares
- Site Admin
- Posts: 42651
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 62 times
- Been thanked: 94 times
- Contact:
Re: Equivalent of VB Sendkey
Marco,
Once that you have the handle of the control try to do this:
PostMessage( hWnd, WM_CHAR, Asc( "a" ) )
Once that you have the handle of the control try to do this:
PostMessage( hWnd, WM_CHAR, Asc( "a" ) )
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Equivalent of VB Sendkey
It seems ok now. Thank you all.
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP