开发者

Help getting the 'Windows Input Simulator' C# interface working

开发者 https://www.devze.com 2022-12-16 23:11 出处:网络
This looks perfect for what I\'m trying to do. I need to stop mucking around with SendInput() and let someone else do it for me!

This looks perfect for what I'm trying to do. I need to stop mucking around with SendInput() and let someone else do it for me!

http://inputsimulator.codeplex.com/

The problem is there's no documentation for getting the code working as simply 开发者_开发问答as it does on the home page there. Can someone help me with the 'other code' I need to have in my program so I can just type InputSimulator.SimulateKeyPress(VirtualKeyCode.SPACE); like he does in the examples?

I've started with:

[DllImport("InputSimulator.dll", CharSet = CharSet.Auto, SetLastError = true)]

which I think is correct. What else do I need?

Thanks!


Project + Add Reference, Browse tab, select the DLL you downloaded.


To get the library working you need to do two things.

  1. Add the InputSimulator.dll to your project, you can do this by right clicking on your project, go to add reference, then use the browse tab, navigate to your InputSimulator.dll (yourFolder\InputSimulator\bin\Release\InputSimulator.dll).

  2. Add the following line to the top of your program, using WindowsInput;

Now, you can access the functionality of the .dll file.

As an example, try the following,

InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_D);


I see that the syntax must be slightly different then they show on the website.

you must create an instance of the InputSimulator, and call it with the syntax below, this is an example on how to simulate a 'shift key down' before a process and a 'shift key up' after a process:

var inputSimulator = new InputSimulator();
inputSimulator.Keyboard.KeyDown((VirtualKeyCode.SHIFT));

//myProcess.Start();

inputSimulator.Keyboard.KeyUp((VirtualKeyCode.SHIFT));

if you want to simulate other keys then use below example:

inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_H);
inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_E);
inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_L);
inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_L);
inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_O);
inputSimulator.Keyboard.KeyPress(VirtualKeyCode.VK_1);
0

精彩评论

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