Simulating keystrokes in Delphi

Posted by James Roland on June 02, 2001

This one might be a tricky one. I have a timer with a 1 minute interval. Every minute i'm wanting to simulate a key press of for example '5' onto the active window (whatever that may be at the time, notepad etc). Maybe there's a way of just copying the number 5 and pasting it into the active window, but so far all i've come up with is the following Delphi code:

PostMessage( GetForeGroundWindow( ), WM_KEYDOWN, VK_NUMPAD5, 0);

Just to recap, i'd open my Delphi application, and then tab to something like notepad. Then in one min from opening the app it would print a 5 on the notepad or whatever the active window is at the time (whatever my cursor is on at the time).

Re: James Roland on June 06, 2001

Nevermind, i've found a component called SendKeys which does the job.

Re: neurolancer on June 07

as far as i remember you can use sethookex api.
talking about components , if u r upto what i think i got a few more components on that line ;)