I'm trying to write a simple program in Visual Studio 2019 that will write a line in the console when a key is pressed using the Keyboard.IsKeyToggled(Key) Method. I've managed to get the code to build, but now this exception appears whenever it gets to the key detection part.
System.DllNotFoundException HResult=0x80131524 Message=Unable to load DLL 'PresentationNative_cor3.dll' or one of its dependencies: The specified module could not be found. (0x8007007E) Source=WindowsBase StackTrace: at MS.Internal.WindowsBase.NativeMethodsSetLastError.SetWindowLongPtrWndProc(HandleRef hWnd, Int32 nIndex, WndProc dwNewLong) at MS.Win32.UnsafeNativeMethods.CriticalSetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc dwNewLong) at MS.Win32.HwndSubclass.HookWindowProc(IntPtr hwnd, WndProc newWndProc, IntPtr oldWndProc) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
I'm very new to C#, so there's likely a simple answer to this. The exception says it is unable to load DLL "PresentationNative_cor3.dll" I tried adding a reference to this DLL, but while I can find it via the file browser when I try to add it it says the DLL is unsupported.
The exception occurs at the third line:
public static void KeyDetect()
{
if (Keyboard.IsKeyToggled(Key.A))
{
DetectLog();
}
}
The Keyboard class can be used in applications that have a window, your application is a console so you should use these instructions to listen for keyboard events in a console application.
You can try the following code to detect the key in console.
static void Main(string[] args)
{
KeyDetect();
Console.ReadKey();
}
public static void KeyDetect()
{
ConsoleKey key;
key = Console.ReadKey(true).Key;
if (key==ConsoleKey.A)
{
Console.WriteLine("You are pressing A");
}
}
User contributions licensed under CC BY-SA 3.0