1. Home
  2. Computing & Technology
  3. Delphi Programming

Sending keys (keystrokes) to another application

By Zarko Gajic, About.com Guide

A unit called SndKey32.pas included on the Delphi installation CD (\Info\Extras\SndKey32.pas), makes it easy to simulate keyboard usage. This unit includes two routines that simulate popular VB routines: Sendkeys and AppActivate. SendKeys takes a PChar as its first parameter and a boolean as its second, like so:

SendKeys('KeyString', Wait) ;

where KeyString is a string of key names and modifiers that you want to send to the current input focus and Wait is a boolean variable or value that indicates whether SendKeys should wait for each key message to be processed before proceeding.

AppActivate also takes a PChar as its only parameter, like so:

AppActivate('WindowName') ;

where WindowName is the name of the window that you want to make the current input focus.

Example syntax: SendKeys('abc1{left}def{end}456{left 4}ghi', True) ;

results in a string "abcdefghi123456" being sent to active window (control with focus)

Delphi tips navigator:
» How to track a user's idle time
« How to call the View Source dialog in WebBrowser

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. Sending keys (keystrokes) to another application from Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.