3

I have been googling FOREVER and I cannot figure out how to invoke keyboard events in C#. Can anyone help me please?

I am using an emulator for a game and I need to trigger keyboard events in my code. I am using WPF in Visual Studio

Jeremy
  • 1,717
  • 5
  • 30
  • 49
  • 2
    Serious games will make it harder on you. If simulating low-level keypresses doesn't work, you usually have to resort to AutoIt which has a driver for sending keys (you can use AutoIt3 in C#!) – SimpleVar Feb 08 '15 at 11:02
  • 2
    How about `SendKeys` - https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys%28v=vs.110%29.aspx – Enigmativity Feb 08 '15 at 11:02
  • Or `SendInput` - http://www.pinvoke.net/default.aspx/user32.SendInput – Enigmativity Feb 08 '15 at 11:03
  • @Enigm `SendKeys` usually work for applications and simple games that get input messages from the OS, but games like League of Legends, WoW and the likes, will usually interpret keystrokes differently, specifically to make it harder to automate them. Same deal with `SendInput` – SimpleVar Feb 08 '15 at 11:04
  • @Enigmativity the form doesn't work – Jeremy Feb 08 '15 at 11:38
  • AutoIt did it. Thank you @YoryeNathan – Jeremy Feb 08 '15 at 12:29

1 Answers1

1

You can use AutoIt3. After the install go to your project references and add:

\Program Files\AutoIt3\AutoItX\AutoItX3.dll

Then you can use its functions. The method to send keyboard keys is Send

AutoItX3Lib.IAutoItX3 a = new AutoItX3Lib.AutoItX3();

a.Send("{NUMPAD1}");

Related

Community
  • 1
  • 1
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
  • I can't believe that after so many years I simply saw this question by "accident" with the solution to make it work with certain games... – BrunoLM Mar 09 '15 at 04:44