Hi all,

I'm pretty sure there's an API for this. Can anybody what it is (or what
they are) and share it here on how to use it?

TIA,
Willianto

Re: How to send a keystroke (say, {ENTER}) to other Windows process? by Man-wai

Man-wai
Thu Feb 28 03:06:15 CST 2008

Willianto wrote:
> Hi all,
>
> I'm pretty sure there's an API for this. Can anybody what it is (or what
> they are) and share it here on how to use it?

You could use window scripting host:

set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Target Window Name"
rem alt-n
WshShell.SendKeys "%N"
rem Alt-O to click ok
WshShell.SendKeys "%O"



--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.24.3
^ ^ 17:04:01 up 1 day 2:52 0 users load average: 0.00 0.00 0.00
? ? (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa/

Re: How to send a keystroke (say, {ENTER}) to other Windows process? by Willianto

Willianto
Thu Feb 28 03:30:49 CST 2008

Hi Man-wai Chang ToDie: (ToDie??? Why??)

Nice to see you again. Long time no see :)

> set WshShell = CreateObject("WScript.Shell")
> WshShell.AppActivate "Target Window Name"
> rem alt-n
> WshShell.SendKeys "%N"
> rem Alt-O to click ok
> WshShell.SendKeys "%O"
>

Ok. I'll try that. But, in a mean time, could anybody with
other-than-wscript solution chime in? I am hoping to use API FindWindows and
SendKeys, but I don't know how.

TIA,
Willianto



Re: How to send a keystroke (say, {ENTER}) to other Windows process? by Man-wai

Man-wai
Thu Feb 28 03:24:40 CST 2008

> Ok. I'll try that. But, in a mean time, could anybody with
> other-than-wscript solution chime in? I am hoping to use API FindWindows and
> SendKeys, but I don't know how.

http://www.news2news.com

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 7.04) Linux 2.6.24.3
^ ^ 17:23:01 up 1 day 3:11 0 users load average: 0.24 0.20 0.09
? ? (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa/

Re: How to send a keystroke (say, {ENTER}) to other Windows process? by Stefan

Stefan
Thu Feb 28 03:36:36 CST 2008


"Willianto" <willianto@deletetelkom.net> schrieb im Newsbeitrag
news:eFbbdpeeIHA.5788@TK2MSFTNGP02.phx.gbl...
>
> Ok. I'll try that. But, in a mean time, could anybody with other-than-wscript solution
> chime in? I am hoping to use API FindWindows and SendKeys, but I don't know how.
Hi Willianto -

There is an API function "keybd_event"
http://eric.aling.tripod.com/PB/tips/pbtip36.htm


hth
-Stefan



--
|\_/| ------ ProLib - programmers liberty -----------------
(.. ) Our MVPs and MCPs make the Fox run....
- / See us at www.prolib.de or www.AFPages.de
-----------------------------------------------------------



Re: How to send a keystroke (say, {ENTER}) to other Windows process? by Christian

Christian
Thu Feb 28 10:04:35 CST 2008

Hi,

here's a little VFP class i've written a few years ago.

Use the api function "SetforegroundWindow" to the window to send the
text to before using it.

Christian

DEFINE CLASS oKeySender AS Custom

#DEFINE KEYEVENT_KEYDN 0x0
#DEFINE KEYEVENT_KEYUP 0x2
#DEFINE VK_SHIFT 0x10
#DEFINE VK_CTRL 0x11
#DEFINE VK_ALT 0x12

FUNCTION Init
DECLARE keybd_event IN USER32 INTEGER, INTEGER, INTEGER, INTEGER
DECLARE SHORT VkKeyScan IN USER32 INTEGER
DECLARE INTEGER MapVirtualKey IN USER32 INTEGER, INTEGER
ENDFUNC

FUNCTION Destroy
CLEAR DLLS "keybd_event", "VkKeyScan", "MapVirtualKey"
ENDFUNC

FUNCTION SendText
LPARAMETERS lcText

LOCAL lnAscii, lcChar, lnVK, nShift, nCtrl, nAlt

FOR xj = 1 TO LEN(lcText)

lcChar = SUBSTR(lcText,xj,1)
lnAscii = ASC(lcChar)

lnVK = VkKeyScan(lnAscii)

IF lnVK = 0
LOOP
ENDIF

lnScan = MapVirtualKey(lnVK,2)
lnExtended = 0
IF lnScan = 0
lnExtended = 1
ENDIF
lnScan = MapVirtualKey(lnVK, 0)

nShift = BITAND(lnVK,0x100)
nCtrl = BITAND(lnVK,0x200)
nAlt = BITAND(lnVK,0x400)
lnVK = BITAND(lnVK,0xFF)

IF nShift > 0
keybd_event(VK_SHIFT,0,KEYEVENT_KEYDN,0)
ENDIF
IF nCtrl > 0
keybd_event(VK_CTRL,0,KEYEVENT_KEYDN,0)
ENDIF
IF nAlt > 0
keybd_event(VK_ALT,0,KEYEVENT_KEYDN,0)
ENDIF

&& press the key
keybd_event(lnVK,lnScan,lnExtended,0)
&& release the key
keybd_event(lnVK,lnScan,BITOR(2,lnExtended),0)

IF nShift > 0
keybd_event(VK_SHIFT,0,KEYEVENT_KEYUP,0)
ENDIF
IF nCtrl > 0
keybd_event(VK_CTRL,0,KEYEVENT_KEYUP,0)
ENDIF
IF nAlt > 0
keybd_event(VK_ALT,0,KEYEVENT_KEYUP,0)
ENDIF

ENDFOR

ENDFUNC

FUNCTION SendKeyCombi
LPARAMETERS lnModifier, lcText

LOCAL lnAscii

IF BITTEST(lnModifier,0)
keybd_event(VK_SHIFT,0,KEYEVENT_KEYDN,0)
ENDIF
IF BITTEST(lnModifier,1)
keybd_event(VK_CTRL,0,KEYEVENT_KEYDN,0)
ENDIF
IF BITTEST(lnModifier,2)
keybd_event(VK_ALT,0,KEYEVENT_KEYDN,0)
ENDIF

DO CASE
CASE VARTYPE(lcText) = 'C'
lnAscii = ASC(lcText)
CASE VARTYPE(lcText) = 'N' OR VARTYPE(lcText) = 'I'
lnAscii = lcText
OTHERWISE
lnAscii = ASC(TRANSFORM(lcText))
ENDCASE

&& press the key
keybd_event(lnAscii,0,KEYEVENT_KEYDN,0)
&& release the key
keybd_event(lnAscii,0,KEYEVENT_KEYUP,0)

IF BITTEST(lnModifier,0)
keybd_event(VK_SHIFT,0,KEYEVENT_KEYUP,0)
ENDIF
IF BITTEST(lnModifier,1)
keybd_event(VK_CTRL,0,KEYEVENT_KEYUP,0)
ENDIF
IF BITTEST(lnModifier,2)
keybd_event(VK_ALT,0,KEYEVENT_KEYUP,0)
ENDIF
ENDFUNC

ENDDEFINE