How to perform a right click in a coded workflow?

I want to perform context click or right click against an element using my code. I know left click like this:
myScreen.Click(“elementName”);

But I see no option to do a context click.

Hey @Priyesh_Tuli
You can try this way:


[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;

public static void RightClick()
{
    mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}

You need to use an overload with the “ClickOptions” object. Using it you can configure which mouse button will be used (among other options).

This would be similar to what you already use: Activities - Click

@Priyesh_Tuli

Please try like this

screen.Click("Button1",ClickType.CLICK_SINGLE,MouseButton.BTN_RIGHT);

cheers

1 Like

Another option (in my case, overload with “ClickType” and “MouseButton” isn’t available).

screen.Click("Button1", NClickType.Single, NMouseButton.Right);
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.