keyboard typing with c#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I make C# type to a screen? For instance make a common sentence or
closing type into word by hitting a button (essentially a keyboard macro).
Also timing has to be considered...for instance i want to type tab, then the
left arrow, then tab, then the left arrow, then back, then wait 3o seconds,
then type tab again etc...
 
gl,

In order to simulate keyboard input, you should check out the SendKeys
class, and the static methods on it. It is located in the
System.Windows.Forms namespace.

Hope this helps.
 
gl said:
How can I make C# type to a screen? For instance make a common sentence or
closing type into word by hitting a button (essentially a keyboard macro).
Also timing has to be considered...for instance i want to type tab, then the
left arrow, then tab, then the left arrow, then back, then wait 3o seconds,
then type tab again etc...

Look into System.Windows.Forms.SendKeys.
 
Will this method work for writing out to a separate application? For instance
i want to use a .net for writing to word, ie, etc. A quick glance at sendkeys
looks like it will only work within the program/form. I want it to type
characters into outside programs. Is this possible?

Thank you for your help.

Nicholas Paldino said:
gl,

In order to simulate keyboard input, you should check out the SendKeys
class, and the static methods on it. It is located in the
System.Windows.Forms namespace.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

gl said:
How can I make C# type to a screen? For instance make a common sentence or
closing type into word by hitting a button (essentially a keyboard macro).
Also timing has to be considered...for instance i want to type tab, then
the
left arrow, then tab, then the left arrow, then back, then wait 3o
seconds,
then type tab again etc...
 
gl said:
Will this method work for writing out to a separate application? For instance
i want to use a .net for writing to word, ie, etc. A quick glance at sendkeys
looks like it will only work within the program/form. I want it to type
characters into outside programs. Is this possible?

It sends keystrokes to whatever the active application is - the one
with focus. You'll need to make sure that the program you're interested
in is active first, of course.

I've used it to launch an editor and then tell the editor to go to a
specific line. (It looks pretty odd to see the "Goto line" dialog pop
up on the screen, but it works well enough.)
 
Back
Top