We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › negative mouseposition values
Page Index Toggle Pages: 1
negative mouseposition values ? (Read 654 times)
negative mouseposition values ?
May 7th, 2007, 11:11pm
 
hello,

is it possible to get negative values for mouseX() and mouseY() once the mouse moves out of the active window ?
it's just that coming from lingo & director i used that a lot and i kind of miss it...

so when the mouse goes to the left, in director you get values getting less even if the mouse is moving beyond the left border of the window. (movement: starts at 100, goes to 0, more left would be -100, -200 etc.)

any ideas ?

all the best

lia.-




Re: negative mouseposition values ?
Reply #1 - May 8th, 2007, 7:08am
 
Previously posted at: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1159137951;start=0#0

Code:

void setMouseXY()
{
if(mouseX>=0 && mouseX<width && mouseY>=0 && mouseY<height) return;
Point mouse, winloc;
mouse = MouseInfo.getPointerInfo().getLocation();
winloc = frame.getLocation();
if(!frame.isUndecorated()){
winloc.x += 3;
winloc.y += 29;
}
mouseX = mouse.x-winloc.x;
mouseY = mouse.y-winloc.y;
}


best
yonas
Re: negative mouseposition values ?
Reply #2 - May 9th, 2007, 6:21pm
 
hi yonas,

thanks for your answer, but something doesn't work, i tried importing the core, cause it got some error "no field named "mouse" was found....., however there is an accessible field "mouseEventMethods" whose name closely matches the name "mouse" .....

what would i need to do to be able to use mouse, winloc and Point in processing?


-----------------------------------

import processing.core.*;
 
void setup(){
size(400,400);
background(255);
}


void draw(){
setMouseXY();
println(mouseX);

}



void setMouseXY()  
{

// your code here ...
}

-----------------------------------

all the best

lia.-
Re: negative mouseposition values ?
Reply #3 - May 9th, 2007, 8:55pm
 
This works fine for me..
Removed the if-sentence, it was causing problems Tongue
Hope it works for you as well

Code:

import processing.core.*;

void setup(){
size(400,400);
background(255);
}


void draw(){
setMouseXY();
println(mouseX);
}


void setMouseXY()
{
Point mouse, winloc;
mouse = MouseInfo.getPointerInfo().getLocation();
winloc = frame.getLocation();
if(!frame.isUndecorated()){
winloc.x += 3;
winloc.y += 29;
}
mouseX = mouse.x-winloc.x;
mouseY = mouse.y-winloc.y;
}


seltar
Re: negative mouseposition values ?
Reply #4 - May 9th, 2007, 10:01pm
 
hi,

i am still getting this:
No accessible field named "MouseInfo" was found in type "Temporary_3310_3773".

my java version (mac osX):
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-112)
Java HotSpot(TM) Client VM (build 1.5.0_06-64, mixed mode, sharing)


all the best

lia.-



Re: negative mouseposition values ?
Reply #5 - May 9th, 2007, 10:22pm
 
That's very odd, since MouseInfo is a variable, not a field.. i sounds like your code doesn't quite match the code psoted, since I don't see how you could get that error, from the example code.
Re: negative mouseposition values ?
Reply #6 - May 9th, 2007, 10:29pm
 
hi,

a reduced version would be:


import processing.core.*;
 
void setup(){
size(400,400);
background(255);
println(MouseInfo.getPointerInfo().getLocation());
}

but the same error occurs...

L.-
Re: negative mouseposition values ?
Reply #7 - May 9th, 2007, 10:36pm
 
Works fine for me in procesing.

Are you doing this in eclipse?
If so try adding import java.awt.*;
Re: negative mouseposition values ?
Reply #8 - May 9th, 2007, 10:46pm
 
hi,

i was just trying it inside of ps1024 ....

tnx

L.-
Re: negative mouseposition values ?
Reply #9 - May 9th, 2007, 11:01pm
 
I don't know what else to suggest to be honest.

However, if you're writing in processing, you don't need the "import processing.core.*" line, processing does some munging behind the scenes to add such things.
Re: negative mouseposition values ?
Reply #10 - May 10th, 2007, 12:19am
 
MouseInfo is new in java 1.5 ... probably lia has 1.4.2.

not sure how to get the mouseposition beyond the frame in 1.4.2 though.

F
Page Index Toggle Pages: 1