Send keystrokes to an application (from a variable)


How can i send keystrokes to a focused window ?
Those keystrokes should come from a variable !

For example :

Var  TheWord:String;



Thanks in advance.
LVL 16
CodedKSenior Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZhaawZSoftware DeveloperCommented:
Try this. It's similar to what I'm using to show winamp now-playing info in any window, so I think it should work (I can't check it because I just reinstalled system and do not have Delphi yet, heh).

  procedure SendInfo;
    pid1 : cardinal;
    pid2 : cardinal;
    wind : cardinal;
    num  : integer;
    text : string;
  pid1 := GetWindowThreadProcessId(GetForegroundWindow);
  pid2 := GetWindowThreadProcessId(wnd);
  AttachThreadInput(pid1, pid2, true);
  wind := GetFocus;
  AttachThreadInput(pid1, pid2, false);
  wsprintfA(@text, '·· %s ·· %ukbps ·· %u:%02u ··'#13, tmp, kbps, mins, secs);
  text := 'some string';
  for num := 1 to length(text) do PostMessage(wind, wm_char, byte(text[num]), 0);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodedKSenior Software EngineerAuthor Commented:
Thang you ZhaawZ :)
ZhaawZSoftware DeveloperCommented:
glad to help ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.