**Duplicating KeyDown events, without pressing a key**
My question concerns KeyDown events.
How do i trigger a KeyDown event without pressing a key.
I would like to create a program that will press the UpArrow key every 3 minutes.
This interaction will be used to trigger a move forward action every 3 minutes in a game i play.
Please any help will be greatly appreciated.
[333 byte] By [
slapper] at [2007-11-20 11:48:06]

# 1 Re: **Duplicating KeyDown events, without pressing a key**
I'm not aware of any .NET function that will provide this functionality, but there is one called SendInput (http://msdn2.microsoft.com/en-us/library/ms646310.aspx) in the Win32 API.
You should be able to find example on the web on how to invoke this from a .NET application.
- petter
# 3 Re: **Duplicating KeyDown events, without pressing a key**
Sorry i should mention im only a novice programmer, ive used microsoft visual studio 2005, c# for 6 months now.
Ive looked into SendInput method but it does not appear. Am i meant to be using a certain library?
Im pretty sure this problem is an easy solution, i really want to learn how its done, if anyone has experience with this and create an example and everything i need with it i would be to to happy.
I can create the random time interval needed, but the key that needs to be sent is the UpArrow key
# 4 Re: **Duplicating KeyDown events, without pressing a key**
Jmcil = my hero
I used what you gave me and it kept typing the desired key on a note pad. Im going to now try it in my game with the up arrow.
Only problems i can see happening is conflict between an active window and the game.
Will post if i have any more problems
# 5 Re: **Duplicating KeyDown events, without pressing a key**
Most interaction with external applications requires invoking the Windows API, of which SendInput is part. You could test to make sure that your game window had focus before calling SendKeys.Send, but that would require invoking the Windows API anyway, so in that case you may as well just use SendInput and you wouldn't have to care which window had focus.