c# - 如何使用 C# SendKeys 以编程方式按下 Windows 键

标签 c# windows keypress sendkeys

基本上我想在代码中模拟用户点击 Windows 键。我知道有 SendKeys,如果我得到它们的句柄,它允许我将按键发送到窗口,但我无法弄清楚的是我需要得到什么句柄才能发送 Windows 键命令。例如。 Windows 键 + L。仔细阅读后,CTRL-ESC 似乎也应该弹出“开始”菜单,但不确定如何告诉它向 Windows 发送 key (如果可能的话)。任何帮助将不胜感激。

干杯!

最佳答案

我不认为你可以使用 SendKeys 来做到这一点,你需要 p/invoke 一个 API 函数,可能是 keybd_event发送 CTRL+ESC 或 Windows 键。

Here是在 VB 和 here 中以这种方式打开开始菜单的示例是在 pinvoke.net 上带有 C# 签名的 keybd_event。

关于c# - 如何使用 C# SendKeys 以编程方式按下 Windows 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1437405/

相关文章:

C# 查询 - 非静态方法需要目标

c# - 无效操作异常 : The type of the argument object 'Scratch' is not primitive

c# - 获取窗口的投影尺寸

c# - 错误反序列化类型的对象......预期来自命名空间 '......' 的结束元素 ''。从命名空间 'item' 找到元素 ''

c# - WPF: program.exe 不退出 "the process cannot access the file.. used by another process"

python - "OSError: [Errno 22] Invalid argument"在 Windows 上使用 print() 和管道输出

windows - 如何在不重新启动的情况下卸载 Windows 服务并删除其文件

javascript - 为什么 IE 不支持我的输入字段中的特殊字符阻止脚本?

c# - 如何通过键入(Windows 资源管理器详细信息 View )跳转到 DataGridView 中的特定行

jquery - 使用 jQuery 触发按键