c# - 如何将 Ctrl + G 发送到另一个应用程序?
问题描述
我正在尝试使用带有 ForegroundWindow 的 InputSimulator 发送 CTRL + G 键,但它不起作用。使用其他键,它可以按预期工作,例如 Ctrl + A 或 Ctrl + C
我尝试过:
Process[] p = Process.GetProcessesByName("notepad");
if (p != null && p.Length > 0)
{
IntPtr h = p[0].MainWindowHandle;
SetForegroundWindow(h);
InputSimulator sim = new InputSimulator();
sim.Keyboard.ModifiedKeyStroke (VirtualKeyCode.CONTROL, VirtualKeyCode.VK_G) .Sleep (300);
}
或者
Process[] p = Process.GetProcessesByName("notepad");
if (p != null && p.Length > 0)
{
IntPtr h = p[0].MainWindowHandle;
SetForegroundWindow(h);
InputSimulator sim = new InputSimulator();
sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
sim.Keyboard.KeyPress(VirtualKeyCode.VK_G).Sleep(300);
sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL).Sleep(300);
}
也试试:
SendKeys.Send ("^ (g)");
我什至尝试过 keybd_event (user32.dll 函数)
解决方案
推荐阅读
- scala - 在 Scala 中建立列表
- sql - 如何编写用于连接具有多个条件的表的 SQL 查询
- wordpress - 仅在单页中不起作用查询(wordpress)
- php - 导航栏中的链接未指向适当的页面
- javascript - Webpack - TypeError: this[NS] is not a function at childCompiler.runAsChild
- css - 跟随 svg 运动路径时的偏移
- emv - 缺少 EMV 颁发者公钥指数,但需要
- excel - Excel VBA 用组合框替换数据验证列表
- vb.net - 在 vb.net 项目中使用 Visual Studio Code 作为主编辑器
- android - 如何在 collapsingToolbar 中添加 HTML 文本?