右击与.NET的SendKeys [英] Right click with SendKeys in .NET

查看:238
本文介绍了右击与.NET的SendKeys的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#.NET的SendKeys。我有字母,箭头键和输入工作。我无法弄清楚如何发送一个单击右键显示上下文菜单。我知道我可以preSS我的键盘上的按键来做到这一点,但我不知道如何发送味精。我如何?我一派,锯

I am using sendkeys in C# .NET. I have letters, arrow keys and enter working. I cant figure out how to send a right click for the context menu. I know i can press a key on my keyboard to do it but i have no idea how to send the msg. How do i? i googled and saw

new MenuItem().PerformClick();

作为一个解决方案,但我没有看到任何影响。的键被发送到另一个应用程序。

as a solution however i didnt see any affect. The keys are being sent to another application.

推荐答案

您可以包装user32.dll中,的我得到的总体思路,从这里

You can wrap the user32.dll, I got the general idea from here

编辑: 我加入POSX和波西,这将是鼠标的坐标。

I added in posX and posY, which would be the mouse coordinates.

using System;
using System.Runtime.InteropServices;

namespace WinApi
{  
    public class Mouse
    { 
            [DllImport("user32.dll")]
            private static extern void mouse_event(UInt32 dwFlags,UInt32 dx,UInt32 dy,UInt32 dwData,IntPtr dwExtraInfo);

            private const UInt32 MouseEventRightDown = 0x0008;
            private const UInt32 MouseEventRightUp = 0x0010;

            public static void SendRightClick(UInt32 posX, UInt32 posY)
            {
                mouse_event(MouseEventRightDown, posX, posY, 0, new System.IntPtr());
                mouse_event(MouseEventRightUp, posX, posY, 0, new System.IntPtr());
            }    
    }
}

这篇关于右击与.NET的SendKeys的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆