John M. Henreick John M. Henreick - 2 months ago 7
C# Question

Input simulator C# WPF Keeps throwing me errors when trying to use it

So I just recently transferred over from

and I've got a grasp knowledge of it now and I tried using the
class but as you already know thats not possible in WPF, so I did some research and googled for a while and I stumbled upon the

And this code should work just fine with WPF as far as I know, I've added the reference and I've added the namespace

public void PressTheSpacebar()

but it keeps throwing me these 2 errors

The type 'InputSimulator' exists in both 'InputSimulator,
Version=, Culture=neutral, PublicKeyToken=null' and
'WindowsInput, Version=, Culture=neutral,


'VirtualKeyCode' is an ambiguous reference between
'WindowsInput.Native.VirtualKeyCode' and 'WindowsInput.VirtualKeyCode'

A more visual reference would be this

Here is a picture of the errors:

enter image description here


You're creating an ambiguous reference. That means the compiler is not sure from where the method should be called. InputSimulator exists in both namespaces. So the compiler cannot compile properly.

To fix the issue, you need to remove any one of the namespaces. Probably remove System.Windows.Input.

EDIT : I have checked your code. Just these namespaces are required. Remove all other namespaces and build your code. It should work fine.

using System;
using System.Windows;
using System.Speech.Synthesis;
using System.Speech.Recognition;
using System.Net.Sockets;