我尝试为一款游戏制作机器人,但他们有很酷的反像素机器人技术..:D 所以我想......和#34;如果我可以制作一个机器人,只检查光标是否变为手,然后点击,它将工作" .. koz我将需要收集奖金框,当你指向你的光标,它变为"手"光标..
所以我对这个想法感到很高兴..但是... dafuq C#,它无法正常工作!
在C#中 - Cursor.Current只检查表单上的游标状态而不是整个计算机!讨厌呀?
那么..我怎么能得到真正的游标类型状态? (如果它的手,正常的光标......大小的东西或等待等) 我有点绝望了.. 感谢任何好主意!
答案 0 :(得分:4)
好的,我找到了一些东西并使其正常工作,如果有人需要这个代码,那就是代码:
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);