在应用程序外的 Win10 中使用 C# 发送击键 [英] Sending Key Strokes with C# in Win10 outside of app

查看:38
本文介绍了在应用程序外的 Win10 中使用 C# 发送击键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向另一个窗口发送一个简单的 "CTRL+C" 笔画.

I am trying to send a simple "CTRL+C" stroke to another window.

这个想法是从 IE/FF/Chrome/IE/Excel/Word 中抓取文本.无论如何,我尝试使用 SendKeys.Send()SendKeys.SendWait() 和 InputSimulator 的 Keyboard.KeyPress().他们都没有抛出异常(好吧SendKeys.Send(),但这是意料之中的),但实际上他们都没有发送任何东西.

The idea is to grab text from IE/FF/Chrome/IE/Excel/Word. Anyway, I have tried to use SendKeys.Send() and SendKeys.SendWait() and InputSimulator's Keyboard.KeyPress(). None of them throw exceptions (Well SendKeys.Send(), but that's expected) but none of them actually send anything.

我曾尝试只发送信函,但没有任何反应.我将包含代码片段,看看我是否正在做一些真正密集的事情,但我担心它是 Win10 隔离的事情.有没有人在 Win10 中在自己的应用程序之外发送击键很幸运?

I have tried to just send letter presses and nothing happens. I will include code snippets to see if maybe I am doing something real dense but I worry its a Win10 isolation thing. Has anyone had luck sending keystrokes outside of their own app in Win10 yet?

发送键:

public void DoItDamnYou()
{
    SendKeys.SendWait("C");
    MessageBox.Show("Press SHOULD have happened");
}

输入模拟器

public void DoItDamnYouNow()
{
    InputSimulator input = new InputSimulator();
    input.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.VK_D);
    MessageBox.Show("Now we are in the wrapper.");
}

如果有人有任何想法,我将不胜感激.

If anyone has any ideas I would greatly appreciate them.

谢谢

推荐答案

似乎 Sendkeys 在 Windows 10 中被禁用.在 Windows 8.1 中,在注册表中禁用 UAC 我可以像往常一样使用 SendKeys 到 Windows 计算器.在 Windows 10 中,在 Retry Calculator 中禁用 UAC 根本不会启动.启用 UAC 计算器启动,但不接受任何 Sendkeys 命令,但接受直接从键盘发出的 Ctrl+V 和 Ctrl+C(读取并复制到剪贴板).

Seems Sendkeys are disabled in Windows 10. In Windows 8.1 , Diasbling UAC in Registry I can use SendKeys to Windows Calculator as usual. In Windows 10, disabling the UAC in Restry the Calculator will not launch at all. Enabling the UAC the Calculator launches, but is not accepting any Sendkeys Command, but is accepting the Ctrl+V and Ctrl+C (read and copy to Clipboard) issued from directly from Keyboard.

这篇关于在应用程序外的 Win10 中使用 C# 发送击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆