English 中文(简体)
拖放uiautomation
原标题:drag and drop uiautomation

我创建了以下代码,它将鼠标悬停在自动元素的可点击点上,然后鼠标悬停在另一个元素的可单击点上。这应该具有拖放的效果,但它没有这样做。它的行为很奇怪。它似乎只是选择项目而不是拖动。

public static void Main(String[] args)
        {
             contactsGrid.getCell("Cell Data").drag();
             navTree.getNode("Tree Data").drop();
        }

public void drag()
        {
            element.SetFocus();
            ScreenClick.leftDown(element);
        }

public void drop()
        {
            element.SetFocus();
            ScreenClick.leftUp(element);
        }

public static void leftDown(AutomationElement element)
        {
            while (!element.Current.IsKeyboardFocusable)
                element = TreeWalker.RawViewWalker.GetFirstChild(element);

            Point p;
            element.TryGetClickablePoint(out p);

            leftDown((int)p.X, (int)p.Y);
        }

public static void leftUp(AutomationElement element)
        {
            while (!element.Current.IsKeyboardFocusable)
                element = TreeWalker.RawViewWalker.GetFirstChild(element);

            Point p;
            element.TryGetClickablePoint(out p);

            leftUp((int)p.X, (int)p.Y);

        }

public static void leftDown(int x, int y)
        {
            Cursor.Position = new System.Drawing.Point(x, y);
            mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
        }

public static void leftUp(int x, int y)
        {
            Cursor.Position = new System.Drawing.Point(x, y);
            mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
        }
最佳回答

尝试使用mouse_event(MOUSEEVENTF_MOVE|…_ABSOLUTE)代替光标进行移动。位置。

(请注意,它所采用的坐标与普通屏幕坐标不同,因此您必须进行一些映射/缩放,将整个屏幕视为一个0,0到6553565535的空间-有关mouse_event的更多详细信息,请参阅备注部分。)

通常,应用程序通过等待WM_LBUTTONDOWN来实现拖动,并且通常也会期待一些WM_MOUSEMOVE消息,否则它们只会将简单的向上/向下视为点击,而不是拖动。我的猜测是使用Cursor。位置(基本上是SetCursorPos的包装器),您“在不移动的情况下更改光标的位置”-不会生成任何输入消息,所以底层应用程序永远不会收到任何WM_MOUSEMOVE消息,也永远不会意识到它应该进行拖动。

问题回答

暂无回答




相关问题
Where to get the "latest" ASP .NET Preview DLL and Script

I have been trying to download the ASP .NET AJAX Futures but I can only see old versions of the DLL via sample tutorials from other websites. I need the DLL to use the Drag and Drop feature according ...

To MVVM or not to MVVM that is the question [closed]

I am rewriting my windows forms based application and I am going to use WPF. The application relies heavily on drag and drop techniques, in a very graphically environment. The uses "Design" reports ...

Make table rows sortable with YUI

Currently I have a table similar to below: <table id="tbl"> <thead> <tr><th>Example Title</th><th>Title2</th></tr> </thead> &...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Java中校正

当我把档案从桌面上拖到浏览器时,我把浏览器放在重点(Safari或PireFox,现在),我知道一切工作权(拖拉,有回信等)。 我也能够......