Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Get Mouse Position

Discussion in 'Scripting' started by mercuryplutus, Jul 12, 2010.

  1. mercuryplutus

    mercuryplutus

    Joined:
    Jun 27, 2010
    Posts:
    158
    How do i get the mouse x and y position for the entire screen? Not just the unity window.
     
  2. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    147
    hi, use
    Code (csharp):
    1. Input.mousePosition
    it will return Vector2
     
  3. mercuryplutus

    mercuryplutus

    Joined:
    Jun 27, 2010
    Posts:
    158
    Hi emadgh. I need the position on the monitor. Not the unity window.
     
  4. EmadGh

    EmadGh

    Joined:
    Jun 10, 2009
    Posts:
    147
    mmmm... let me think...
    .
    .
    .
    I think I dont know :cry:
     
    PutridEx likes this.
  5. zergmouse

    zergmouse

    Joined:
    Jun 30, 2010
    Posts:
    216
    yea so you would have to use an external "bot" program. I wont tell you how or where to get them. However they are run as standalone applications. I am almost positive that you can not get the mouse location on the whole screen from within Unity without integrating one of these bot programs.

    EDIT: This might help for those of you that are code savy: http://www.codeproject.com/KB/cs/globalhook.aspx
     
  6. mercuryplutus

    mercuryplutus

    Joined:
    Jun 27, 2010
    Posts:
    158
    I managed to use the user32.dll but there are a lot of problems with it. It only works with windows standalone builds and it uses monitor position not unity window position. Thats a problem because i can't get GetCursorPos working. Can only get SetCursorPos working.

    Code (csharp):
    1.  
    2. [DllImport("user32.dll")]
    3.     public static extern int SetCursorPos(int x, int y);
    4.  
    Does anyone know how to make GetCursorPos() work? I think it requires the System.Drawing.dll because of its use of the Point class.
     
  7. zergmouse

    zergmouse

    Joined:
    Jun 30, 2010
    Posts:
    216
  8. mori_morteza

    mori_morteza

    Joined:
    Aug 1, 2010
    Posts:
    1
    Hi .
    I have same problem .

    please help me ... :)

    thanks