mouseLocation method is returning garbage

Discussion in 'Mac Programming' started by WhiteRabbit, May 7, 2009.

  1. WhiteRabbit macrumors newbie

    Joined:
    Jan 11, 2005
    #1
    I can't seem able to get a useful mouse location from NSEvent. I rigged a mouseDown event method to log the mouse coordinates. The method is evoked as expected but the location displayed is unintelligible.
    Code:
    NSPoint location=[NSEvent mouseLocation];
    NSLog(@"{ %d, %d }", location.x, location.y);
    
    The x coordinate is always zero, and the y is a large integer. Mouse movement on x axis changes the "y" number, and y-axis movement has no effect. Also, the "y" number isn't random, in fact it is linear, but one pixel of mouse movement is a few thousand in change.

    I can't seem to make any sense of this at all. Does anyone have any ideas?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    %d is for a signed int. NSPoints x and y are floats. Use %f
     
  3. WhiteRabbit thread starter macrumors newbie

    Joined:
    Jan 11, 2005
    #3
    Well that sure makes a lot of sense. I wonder how I overlooked that.
     

Share This Page