gpt4 book ai didi

C# - 如何获取当前光标状态(如果当前是箭头、手、等待等)

转载 作者:行者123 更新时间:2023-12-02 04:28:16 27 4
gpt4 key购买 nike

我尝试为一款游戏制作一个机器人,但他们有很酷的反像素机器人技术。

所以我想,“如果我可以制作一个机器人,只检查光标是否变为手形然后单击,它就会起作用,”因为我需要收集奖金盒,当你将光标指向它时,它变为“手”光标。

所以我对这个想法非常高兴,但在 C# 中,它不起作用!

在 C# 中 - Cursor.Current 仅检查表单上的光标状态,而不检查整个计算机的光标状态,这不是我想要的。

那么,我怎样才能获得真正的光标类型状态呢? (如果是手,普通光标,调整某些东西的大小或等待等)

最佳答案

好吧,我找到了一些东西并使其正常工作,如果有人需要的话,这里是代码:

    private static string GetCursorState()
{
var h = Cursors.WaitCursor.Handle;

CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out pci);


return pci.hCursor.ToString();
}

[StructLayout(LayoutKind.Sequential)]
struct POINT
{
public Int32 x;
public Int32 y;
}

[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize; // Specifies the size, in bytes, of the structure.
// The caller must set this to Marshal.SizeOf(typeof(CURSORINFO)).
public Int32 flags; // Specifies the cursor state. This parameter can be one of the following values:
// 0 The cursor is hidden.
// CURSOR_SHOWING The cursor is showing.
public IntPtr hCursor; // Handle to the cursor.
public POINT ptScreenPos; // A POINT structure that receives the screen coordinates of the cursor.
}

[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);

关于C# - 如何获取当前光标状态(如果当前是箭头、手、等待等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25367952/

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