简体   繁体   中英

Sending Application Key via SendKeys.Send

I'm making an app that lets you navigate between items using SendKeys. All works pretty well except when I try to send the Application Key (context menu) to do a right click on the selected item.
I use:

SendKeys.Send("{APPSKEY}");

I get an Error saying 'Keyword "APPSKEY" is not valid.'

I googled it and found it on this website:
http://www.autohotkey.com/docs/commands/Send.htm
But i'm guessing that doesn't work for c#.

is there any other way to do a rightclick on the selected item?
is there a way to tell the app where the item is located to move the mouse there and do a right click?

my program can send MouseClicks:

public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.StdCall)]
    public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint 
    cButtons, uint dwExtraInfo);
    private const int MOUSEEVENTF_LEFTDOWN = 0x02;
    private const int MOUSEEVENTF_LEFTUP = 0x04;
    private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const int MOUSEEVENTF_RIGHTUP = 0x10;

    private void MoveCursor(Point loc)
    {
        this.Cursor = new Cursor(Cursor.Current.Handle);
        Cursor.Position = loc;
        Cursor.Clip = new Rectangle(0, 0, 0, 0);
    }

    private void DoMouseClick(bool isLeft)
    {
        int X = Cursor.Position.X;
        int Y = Cursor.Position.Y;
        if (isLeft) mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)X, (uint)Y, 0, 0);
        else mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, (uint)X, (uint)Y, 0, 0);
    }
}

But in order to simulate a right click on that item the app has to know where it is located.

Try

SendKeys.Send("+{F10}");

Regards,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM