2017-06-10 60 views
0

有沒有一種方法可以模擬Windows IoT上特定座標的點擊?UWP:模擬在Windows上的特定座標點擊物聯網

我試着用mouse_event:

mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); 

但是,我得到這個錯誤:

System.EntryPointNotFoundException: 'Unable to find an entry point named 'mouse_event' in DLL 'user32.dll'.'. 

是不是因爲那個函數沒有在Windows的IOT測試版的存在嗎?

我看到有SendInput,但文檔中唯一的語法是C++。是否有可能在Windows IoT的C#中使用它,如果是這樣的話?如果你有一個例子,鏈接它將是非常有用的。我四處搜尋,但我找不到可以在UWP上使用的東西。

這裏是我用於mouse_event的代碼:

[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetCursorPos")] 
private static extern bool SetCursorPos(int X, int Y); 

[System.Runtime.InteropServices.DllImport("user32.dll")] 
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); 

public const int MOUSEEVENTF_LEFTDOWN = 0x02; 
public const int MOUSEEVENTF_LEFTUP = 0x04; 
public const int MOUSEEVENTF_RIGHTDOWN = 0x08; 
public const int MOUSEEVENTF_RIGHTUP = 0x10; 

//... 

public void Click(int x, int y) 
{ 
    SetCursorPos(x,y); 
    mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0); 
    mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0); 
} 

回答

0

既不mouse_event也不SendInput可以在UWP應用中。作爲記載,這些API的是

desktop apps only

如果您是從UWP應用程序(顯然你是哪個)運行此,沒有辦法自動另一個UWP應用。沙箱不會允許這個。這包括UI Automation

+0

哦好吧謝謝。如果你能檢查出它會很好,我就要解決的更大問題發佈了另一個問題。再次感謝! https://stackoverflow.com/questions/44476899/uwp-click-through-a-component-on-page –