代码之家  ›  专栏  ›  技术社区  ›  Cyril Gupta

如何使用Windows API将输入发送到Visual Studio

  •  1
  • Cyril Gupta  · 技术社区  · 17 年前

    我想使用Windows API实现这一点,因为我想开发一个可以与任何应用程序一起全局工作的应用程序(无论您使用的是VS还是写字板,您都应该获得相同的功能)。

    我已经能够通过记事本、写字板等使用EM_ugetsel和EM_REPLACESEL消息成功地做到这一点。但是这些API不适用于VisualStudio或ms word。

    我应该使用什么API才能 2.将输入发送到编辑器。

    我正在用C语言编程。如果你一定要知道我想做什么。。。我正在尝试制作一个通用的Zencodeding端口,它可以在任何编辑器上工作。因此,我们将感谢所有的帮助。

    4 回复  |  直到 17 年前
        1
  •  2
  •   TcKs    17 年前

    为什么不使用System.Windows.Forms.SendKeys类来模拟用户的键盘输入?

    SendKeys.SendWait("^C"); //CTRL+C
    var selectedText = Clipboard.GetText();
    var newText = Replace(selectedText);
    SendKEys.SendWait("^V"); //CTRL+V
    
        2
  •  3
  •   michael noonan    16 年前

    对于第2部分,您可以尝试使用 Windows Input Simulator

    在您的情况下,如果用户可以使用键盘执行任务,此项目将帮助您,否则您需要找到其他解决方案。

    希望这有帮助。

        3
  •  2
  •   Ariel    16 年前

    System.Windows.Automation
    System.Windows.Automation.Provider

    例如,这是一种查找自动化目标元素的方法(例如,典型的win控制):

        public static AutomationElement FindElement(AutomationElement context, PropertyCondition[] conditions)
        {
            // if no conditions, there's no search to do: just return the context, will be used as target
            if (conditions == null)
            {
                return (context);
            }
    
            // create the condition to find
            System.Windows.Automation.Condition condition = null;
            if (conditions.Length <= 0)
            {
                throw (new ArgumentException("No conditions specified"));
            }
            else if (conditions.Length == 1)
            {
                condition = conditions[0];
            }
            else
            {
                AndCondition ac = new AndCondition(conditions);
                condition = ac;
            }
    
            // find the element
            CacheRequest creq = new CacheRequest();
            creq.TreeFilter = Automation.ControlViewCondition;
            using (creq.Activate())
            {
                AutomationElement e = AutomationContext(context);
                AutomationElement target = e.FindFirst(TreeScope.Subtree, condition);
                return (target);
            }
        }
    
        4
  •  0
  •   John Saunders    16 年前

    无论您尝试什么,请务必尽快使用Visual Studio 2010 beta 2进行尝试。该编辑器大部分已经重写,使用早期版本的黑客应该再次测试。

    推荐文章