Created
August 3, 2012 16:56
-
-
Save DexterHaslem/3249480 to your computer and use it in GitHub Desktop.
AutomationElement pinvoke right click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add references WindowsBase, UIAutomationClient, UIAutomationTypes | |
// using System.Windows.Automation; | |
// using System.Windows; | |
[DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); | |
public void RightClick(AutomationElement element) | |
{ | |
const int WM_LBUTTONDOWN = 0x0201; | |
const int WM_LBUTTONUP = 0x0202; | |
Point point = element.GetClickablePoint(); | |
object processId = element.GetCurrentPropertyValue(AutomationElement.ProcessIdProperty); | |
AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children,new PropertyCondition(AutomationElement.ProcessIdProperty, processId)); | |
Int32 hWnd = window.Current.NativeWindowHandle; | |
double x = point.X; | |
double y = point.Y; | |
Int32 value = ((int)x)<<16 + (int)y; | |
SendMessage(new IntPtr(hWnd), WM_LBUTTONDOWN, IntPtr.Zero, new IntPtr(value)); | |
SendMessage(new IntPtr(hWnd), WM_LBUTTONUP, IntPtr.Zero, new IntPtr(value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment