为什么会出现此错误,我该如何解决?

Why does this error occur, and how can I fix it?

我有一个 C# 问题,使用 KeyboardEventArgs class 我不知道如何解决这个问题。错误代码为

No argument was given, that corresponds to the formal parameter "keyboard" of "KeyboardEventArgs.KeyboardEventArgs (KeyboardDevice, int)

我在互联网上搜索但一无所获。如果你能帮助我,请使用这个例子向我解释并且对初学者友好。我很感激任何反馈:)

您正在尝试继承 KeyboardEventArgs,它没有无参数构造函数,因此您需要为构造函数实现输入参数。像

    class Keys : System.Windows.Input.KeyboardEventArgs
{
    public Keys(KeyboardDevice keyboard, int timestamp) : base(keyboard, timestamp)
    {
    }
}

对了,你可以看看https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/KeyboardEventArgs.cs

中的KeyboardEventArgs源码