SendKeys 是 C# 中的一个类,它位于 System.Windows.Forms 命名空间中。这个类允许你模拟键盘按键操作,例如按下、释放和输入文本等。以下是一些使用 SendKeys 的示例:
using System; using System.Windows.Forms; namespace SendKeysExample { class Program { static void Main(string[] args) { // 模拟按下 "A" 键 SendKeys.Send("A"); // 模拟按下组合键 Ctrl + C SendKeys.Send("+C"); // 模拟释放 "A" 键 SendKeys.Send("{RELEASE}"); } } } using System; using System.Windows.Forms; namespace SendKeysExample { class Program { static void Main(string[] args) { // 输入文本 "Hello, World!" SendKeys.Send("Hello, World!"); } } } using System; using System.Windows.Forms; namespace SendKeysExample { class Program { static void Main(string[] args) { // 模拟按下组合键 Ctrl + Alt + Delete SendKeys.Send("+Alt+Delete"); } } } 需要注意的是,SendKeys 类只能模拟 Windows 操作系统下的键盘操作。如果你需要在其他操作系统(如 macOS 或 Linux)上进行类似的操作,你可能需要使用其他库或方法。