FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Beyond Categories
(Moderator: REAS)
   unlimited mouse movement
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: unlimited mouse movement  (Read 7843 times)
020200

WWW
unlimited mouse movement
« on: Dec 7th, 2004, 11:28am »

Hi fellow processing coders!
 
I have a problem with mouseDragging. My goal is to make a somewhat "unlimited" rotation-interaction with the mouse. I want to make it like this:
 
1. If you press the mousebutton, the cursor hides.
2. Then you can rotate the object on the screen in every possible direction.
3. If you stop pushing the mousebutton, the cursor will be in the same position like before (under 1.)
 
The problem that remains is: if i hide the cursor, the cursor's "still there" and the rotation is only applied until the cursor hits the border of the screen. but i want the rotation to go on "forever" if the user wants to do it "forever"...
 
here is the link
http://www.2063music.de/p5/mouse-box/
 
and my code
Code:

float a = 0.00;
float fx, fy;
int t = 0;
float mousescale =  0.007;
 
 
void setup () {
  size(800,600);
  framerate(30);
  smooth();
  cursor();
  ellipseMode(CENTER_DIAMETER);
  noFill();
  stroke(245, 150, 40);
}
 
void loop() {
  background(90, 40, 40);
  //a+=0.05;
  if (keyPressed) {
  if (key == UP) {t+=3;}
  if (key == DOWN) {t-=3;}
  }
  translate(width/2, height/2, t);
  rotateX(fy);
  rotateY(fx);
  box(200);
}
 
void mouseDragged() {
  noCursor();
  if (mouseX < pmouseX) {
    fx = fx - (pmouseX-mouseX)*mousescale;
  }
  if (mouseX > pmouseX) {
    fx = fx + (mouseX-pmouseX)*mousescale;
  }
  if (mouseY > pmouseY) {
    fy = fy + (pmouseY-mouseY)*mousescale;
  }
  if (mouseY < pmouseY) {
    fy = fy - (mouseY-pmouseY)*mousescale;
  }
}
 
void mouseReleased() {
  cursor();
}

 
 
fry

WWW
Re: unlimited mouse movement
« Reply #1 on: Dec 7th, 2004, 6:58pm »

it's a java limitation that the mouse is tracked only inside of the space of your sketch. however, if you hold the mouse down, and then drag outside the window, you'll keep getting new mouse positions.
 
020200

WWW
Re: unlimited mouse movement
« Reply #2 on: Dec 8th, 2004, 3:36pm »

Yes, but unfortunatelly not if the mouse reaches the (physical?) bottom of the screen....
 
TomC

WWW
Re: unlimited mouse movement
« Reply #3 on: Dec 8th, 2004, 4:21pm »

Similar problem (with a pointer from mKoser to a fix) here: http://processing.org/discourse/yabb/board_Contribution_Respons_ive_action_display_num_1101956881.html
 
If you use the AWT Robot suggestion, the thing to do is to hide the cursor and reset its position back to the centre every frame, and only deal with the change in position.  That way you get the maximum range out of the mouse.  When the user clicks you need to remember the current mouse position, and when the user unclicks you can restore it.
 
toxi

WWW
Re: unlimited mouse movement
« Reply #4 on: Dec 8th, 2004, 7:35pm »

the robot is probably the way to go. you only have to sign the exported .jar file in order to use the functionality as this can be potentially malicious code. so also make sure it's working properly or else you might cause some furious response from users...
 
to sign a .jar file you'll first need to create a signature with java's keystore manager. so open a shell and type (replace nickname and password with your own):
 
Code:
keytool -genkey -alias myNickName -keypass myAliasPassword

 
then answer all the questions and once you have created your key pair continue with signing the jar:
 
Code:
jarsigner /path/to/myJAR_toBeSigned.jar myNickName

 
...and bob's your mother's brother.
 
an example can be found here: http://www.toxi.co.uk/p5/permissions/
 
btw. i have assumed that you have a JDK installed and that its /bin directory is in your PATH variable (on windows, not sure about other systems)
 

http://toxi.co.uk/
020200

WWW
Re: unlimited mouse movement
« Reply #5 on: Dec 9th, 2004, 12:03am »

Ah, thanks a lot. I had exactly the same idea to solve the problem this way. This looks like some voodoo to me. Maybe i can read somewhere about the "catch" and the "try"?
 
Code:

void loop(){
  if (!keyPressed) {
    try {
 // Move the cursor
 Robot robot = new Robot();
 robot.mouseMove((int)(500+400*sin(x)),(int)(400+200*sin(HALF_PI+x*1.8))) ;
 x+=0.01;
    } catch (AWTException e) {
    }
  }
}
 
TomC

WWW
Re: unlimited mouse movement
« Reply #6 on: Dec 9th, 2004, 12:55am »

http://java.sun.com/docs/books/tutorial/essential/exceptions/
 
 
flight404

WWW Email
Re: unlimited mouse movement
« Reply #7 on: Dec 9th, 2004, 11:32pm »

Okay, I feel both angry and stupid all rolled into one.  I accepted the cert, Toxi, and it took control of my mouse.  How cute.  But now how do I get it back?  I tried force quitting safari, but it wouldnt let me.  I tried rebooting, and now i get no mouse input what-so-ever.  So essentially, my computer is dead.
 
1) anyone?  how do i fix this.
2) Toxi, you might want to have more of a specific disclaimer on your example link. Maybe I didnt read between the lines properly, but I never got the impression that this was a semi-permanent effect.
 
r
 
 
UPDATE----------------------------------------
Okay, the 3rd reboot seems to have done the trick.  Malicious indeed.  I feel so violated.
« Last Edit: Dec 9th, 2004, 11:36pm by flight404 »  
toxi

WWW
Re: unlimited mouse movement
« Reply #8 on: Dec 10th, 2004, 5:35pm »

oh no! that can only be counted as "force majeure" and was totally unintentional! needless to say i'm v.sorry about that mishap. i've just updated the code to behave a lot more nicely, but i'm sure that taught you and i don't blame you if you won't give it another go...
 
the malicious "cancer code" is now benign
 
btw. as long as the browser window itself still has the focus, you should be able to just use the keyboard shortcut (Command+W) to close the window, no?
« Last Edit: Dec 10th, 2004, 5:36pm by toxi »  

http://toxi.co.uk/
020200

WWW
Re: unlimited mouse movement
« Reply #9 on: Dec 10th, 2004, 7:04pm »

on Dec 8th, 2004, 7:35pm, toxi wrote:

to sign a .jar file you'll first need to create a signature with java's keystore manager. so open a shell and type (replace nickname and password with your own)
*snip*

ho, that is too complicated for unlucky me beginner....
so i don't get the applet in he web, but on my p5-sketchbook it works fine. you can mail me for the whole code (or should i post it)
 
finnally i found a solution, but i think this is the opposite of an elegant solution:
 
1. i set the mousepointer with the robot to a position (say: 350, 350)
2. then i took the coords of the pointer, to save it in variables (once!)
3. then i always calculate in the mouseDragged commando the difference between the mouseX / mouseY and the  stored variable, then i turn the pointer to back to the original value again. sounds messy it think it is.  
 
here is the main part:
 
Code:
void mouseDragged() {
noCursor();
  try {
    // Move the cursor
    Robot robot = new Robot();
    robot.mouseMove((int)(350),(int)(350));
  } catch (AWTException e) {
  }
 
  fx+=(mouseX-mx)*mousescale;
  fy+=(mouseY-my)*mousescale;
}
 
void mouseReleased() {
  cursor();
}
« Last Edit: Dec 10th, 2004, 7:06pm by 020200 »  
020200

WWW
Re: unlimited mouse movement
« Reply #10 on: Dec 10th, 2004, 11:44pm »

ahm, yes.
here it is.
http://www.2063music.de/p5/mouse-box-solved/mouse_box_solved.pde
 
flight404

WWW Email
Re: unlimited mouse movement
« Reply #11 on: Dec 11th, 2004, 3:52am »

Force quitting had no effect (although I was able to bring up the force-quit window).  Cmd-tab wouldnt switch to other applications.  And from that point on, keyboard was completely unresponsive.
 
I did learn my lesson, but it felt like a dare...
 
Come on, buddy, I dares ya...
 
 
michael05

WWW
Re: unlimited mouse movement
« Reply #12 on: Feb 3rd, 2005, 12:37pm »

i do not like the robot solution. that's why i wrote a solution with jinput (part of javagames). it works great. i am getting relative mouse movement values. it is possible to work with the keyboard and gamepads, too.
 
if i will find the time this evening i will write a class that is accesssible within processing.
 
https://jinput.dev.java.net/
 

°°°°°°°°°°°°°°°°°°°°
http://www.m05.de
michael05

WWW
Re: unlimited mouse movement
« Reply #13 on: Feb 3rd, 2005, 10:44pm »

done.. if anyone needs it:
http://dev.m05.de/p5/AbsoluteMouse/
 
the library uses the jinput library (https://jinput.dev.java.net) by the Game Technology Group at Sun Microsystems. just put the content of the AbsoluteMouse.zip in your code folder. it is just a windows version (uh..). but it should be no problem to port it to linux and os x (the source is enclosed).
 
please read the readme.txt
 
Code:

// AbsoluteMouse by michael zoellner
// http://www.m05.de
// 20050203
 
AbsoluteMouse aMouse;
 
void setup()
{
  size(800,600);
  background(50);
  //initialize the class
  // new AbsoluteMouse(); default controller 0 (mouse)
  // new AbsoluteMouse(int controller);
  // new AbsoluteMouse(int controller, long delay);
  aMouse = new AbsoluteMouse();
}
 
void loop()
{
  // aMouse.absMouseX is the absolute pixel position
  // aMouse.mouseX is the relative movement
  println(aMouse.absMouseX+" "+aMouse.absMouseY+" "+aMouse.relMouseX+" "+aMouse.relMouseY);
 
  // example
  background(50);
  translate(width/2, height/2, 0);
  float rotation = aMouse.absMouseY/1000.0f;
  rotateY(rotation);
  box(200);
}
« Last Edit: Feb 23rd, 2005, 10:52am by michael05 »  

°°°°°°°°°°°°°°°°°°°°
http://www.m05.de
Pages: 1 

« Previous topic | Next topic »