gpt4 book ai didi

c# - 在 .NET 中使用 SendKeys 右键单击

转载 作者:太空宇宙 更新时间:2023-11-03 19:35:18 24 4
gpt4 key购买 nike

我在 C# .NET 中使用 sendkeys。我有字母、箭头键和输入工作。我不知道如何为上下文菜单发送右键单击。我知道我可以按键盘上的一个键来执行此操作,但我不知道如何发送消息。我如何能?我用谷歌搜索了一下

new MenuItem().PerformClick();

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

最佳答案

您可以包装 user32.dll,I got the general idea from here

编辑:我添加了 posX 和 posY,这将是鼠标坐标。

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());
}
}
}

关于c# - 在 .NET 中使用 SendKeys 右键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2024088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com