using UnityEngine;
using System;
using System.Runtime.InteropServices;
// Create a point struct.
public struct Point
{
public int x;
public int y;
}
class Cursor_Move : MonoBehaviour {
[DllImport("user32.dll")]
static extern bool GetCursorPos(IntPtr buffer);
Point p;
IntPtr pnt;
void OnGUI () {
try {
// Initialize unmanged memory to hold the struct.
pnt = Marshal.AllocHGlobal(Marshal.SizeOf(p));
// Copy the struct to unmanaged memory.
Marshal.StructureToPtr(p, pnt, false);
// Call api function
GetCursorPos(pnt);
// Set this Point to the value of the
// Point in unmanaged memory.
p = (Point)Marshal.PtrToStructure(pnt, typeof(Point));
} finally {
// Free the unmanaged memory.
Marshal.FreeHGlobal(pnt);
}
GUI.Label (new Rect (10, 10, 100, 20), "x: "+(p.x).ToString()+" y: "+(p.y).ToString());
}
}