开发者

c# console application to repeat keyboard presses?

开发者 https://www.devze.com 2022-12-14 18:50 出处:网络
I am trying to make a simple macro program to repeat keyboard key presses and I am havin开发者_Python百科g trouble finding out how to fire a keyboard event, anyone have any hints?If you just want a si

I am trying to make a simple macro program to repeat keyboard key presses and I am havin开发者_Python百科g trouble finding out how to fire a keyboard event, anyone have any hints?


If you just want a simple script (i.e. it doesn't have to be C#) it would be much easier to do from VBScript with the SendKeys method. That does exactly what you are looking for.

Edit: Ok, so it seems there is a SendKeys class in .NET which I will assume does the same thing.


As tommieb75 mentioned, don't reinvent the wheel. Just take AutoIt3.


ConsoleKeyInfo info;
do {
    info = Console.ReadKey(true);
    if ((info.Modifiers & ConsoleModifiers.Alt) > 0) Console.Write("Alt+");
    if ((info.Modifiers & ConsoleModifiers.Control) > 0 ) Console.Write("Control+");
    if ((info.Modifiers & ConsoleModifiers.Shift) > 0) Console.Write("Shift+");
    Console.WriteLine(info.Key.ToString());
 } while (info.Key != ConsoleKey.Escape);


Here is a library for simulating keyboard and mouse activities: http://inputsimulator.codeplex.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消