SendKeys

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > UI (User Interface) > Windows API >

SendKeys

 

Description

 

Send text to the current top-level window simulating keyboard keystrokes.

 

Syntax

 

hWnd = Sendkeys(TextToSend [, mSec])

 

Returns

 

Number: handle to the window if found

 

Parameters

 

Name

Type

Optional

Meaning

TextToSend

String

No

Text to send

mSec

Number

Yes

Milliseconds to wait after text has been sent.

 

Remarks

 

SendKeys function uses keybd_event API function. keybd_event API has been superseded by SendInput API. For this reason SendString function has been developed.

 

Sendkeys function should emulate most of the same rules as the Visual Basic Sendkeys.

 

You can send these codes:

{ENTER}

{ESC}

{UP}

{DOWN}

{LEFT}

{RIGHT}

{BACKSPACE} or {BS}

{HOME}

{END}

{PGUP}

{PGDN}

{TAB}

{DEL} or {DELETE}

{INS} or {INSERT}

{WIN}

{PRTSC}

(CAPSLOCK}

{NUMLOCK}

{SCROLLLOCK}

{HELP}

{F1} to {F16}

{SLEEP 1000} <-- 1000 miliseconds

{AppActivate WindowName}   <-- switches to this window

 

Precede characters with + for Shift, ^ for Ctrl, % for Alt

 example: ^p       would be Ctrl-p

 

You can also group characters for shift/ctrl/alt with parentheses ()

 example: ^%({DEL}{DEL})  would be Ctrl-Alt-Del twice

 

To send these special characters {+^%~( as plain characters enclose them in braces

 example: {{}      would just send  {

 

To send a key multiple times inclose it in braces with a number like {h 3}

 example: {DEL 41)  would send DELETE key 41 times

 

Restrictions

 

See also

 

 SendString

 

Examples

 

Sendkeys("This is my text to send.{ENTER}")