Creating a script to record mouse movements and run in the background.
in
Programming Questions
•
2 years ago
So this is for my MySQL and XML class. Here's what I want this script to do/goals for the script:
1. Run in the background while still recording movements of goal 3.
2. Run in a browser...probably inserted with HTML.
3. Record mouse movement.
4. Every second create a square on the X and Y axis of wherever the mouse is.
5. Every minute create a circle in the same on xy axis.
6. when the circle is created, skip step 4.
7 Every hour create an ellipse on the xy axis of wherever the mouse is at that second/hour.
8. when ellipse is created skip steps 4 and 5.
9. move from background to foreground after closing the browser as a pop up.
10. have the option to save step 9 pop up result.
11. this whole thing to be as large as the browser window (but still in the background. this should probably be step 3...).
If you know an answer to any of the above (excluding steps 3, 4,5, and 7) please respond. I'm not expecting one person to answer all of those...although that'd be way cool :).
Ok. Here are the scripts I have. The first one is for steps 3,4,5, and 7. The other scripts don't work. and I need to add steps 6, and 8 into the (3457) script.
boolean debug = true; //Provide feedback
int boxSize = 20;
int circleSize = 40;
int ellipseSize = 80;
int sketchWidth = 800;
int sketchHeight = 800;
int boxStart, circleStart, ellipseStart, colorStart, colorStartB, skipStart, skipRect; //Timing variables
//I don't think I need any of these. Just in case.
void setup() {
smooth();
noStroke();
frameRate(30);
size(sketchWidth, sketchHeight);
background(0);
boxStart = millis();
skipStart = millis();
skipRect = millis();
circleStart = millis();
ellipseStart = millis();
colorStart = millis();
colorStartB = millis();
background(127);
}
void goStartOver() {
}
void draw() {
//Draw one box a second; this works
//---------------------------------------------------------
//---------------------------------------------------------
if((millis() - boxStart) >=1000) {
//draw a box, but based on mouse x and y.
rect(mouseX, mouseY, boxSize, boxSize);
boxStart = millis();
if(debug) {
println("box");
}
}
//this works right now. it changes color every 60 seconds.
if((millis() - colorStart) >= 60000) {
fill(random(255), random(255), random(255), random(150,255));
colorStart = millis();
if(debug) {
println("boxcolor");
}
}
//Generate circle every 60 seconds. Need to find a way to cancel the rectangle.
if((millis() - circleStart) >=60000) {
ellipse(mouseX, mouseY, 70, 70);
if(debug) {
println("circle");
}
circleStart = millis();
}
//generate one elipse every hour.
if((millis()- ellipseStart) >= 3600000) {
ellipse(mouseX, mouseY, 90, 30);
if(debug) {
println("ellipse");
}
ellipseStart = millis();
}
}
Ok. Next script. This one is meant to record the mouse xy even if the mouse cursor is off the screen/browser. This is a directly copied example that returns the error: "Cannot find class or type named "Point"". If I insert an empty class named Point I get the error:" cannot convert from point to sketch____.Point.
import java.awt.MouseInfo;
int mX, mY;
void setup(){}
void setMouseXY()
{
mX = mouseX; mY = mouseY;
if(mouseX>=0 && mouseX<width && mouseY>=0 && mouseY<height){
Point mouse, winloc;
mouse = MouseInfo.getPointerInfo().getLocation();
winloc = frame.getLocation();
if(!frame.isUndecorated()){
winloc.x += 3;
winloc.y += 29;
}
mX = mouse.x-winloc.x;
mY = mouse.y-winloc.y;
}
}
void draw(){
setMouseXY();
background(0);
stroke(255);
line(mX, 0, mX, height);
line(0, mY, width, mY);
println( "mX is " + mX + " and mY is " + mouseY );
}
void draw(){
setMouseXY();
background(0);
stroke(255);
line(mX, 0, mX, height);
line(0, mY, width, mY);
println( "mX is " + mX + " and mY is " + mouseY );
}
Here's a script I've tried to just record the mouse xy (another way I was going to try that on a webpage^ was to record the info, upload it to a database and then run the rect/circle/ellipse script there...and then return the result.
Point mouse;
void setup() {
size(100,100);
}
void draw(){
mouse = MouseInfo.getPointerInfo().getLocation();
println( "mX is " + mouse.x + " and mY is " + mouse.y );
}
This next one attempts to insert the .jar file into an html page. It's one of the simpler ways I've tried to insert it. It returns a blank page with the date. I don't know how to include the clockfail2.jar file with this script...or how to tell the html document where the app is. So that may be the problem...
<HTML>
<HEAD>
<TITLE>Signed Applet Example</TITLE>
</HEAD>
<BODY>
<script type="text/javascript">
document.write("<p>"+Date() + "</p>");
getApplet(clockfail2.jar);
</script>
<APPLET archive="clockfail2.jar" code="clockfail2.jar" width=800 height=800>
</APPLET>
</BODY>
</HTML>
Here's another way of inserting it I've tried.
<html>
<head>
//I also converted it into a javascript type. I think. It was 8 hours ago and its 7 am.
<script src="processing.js"></script>
</head>
<p>Clock</p>
<p><canvas> id="canvas1" width="200" height="200"></canvas></p>
<script id="script1" type="text/javascript">
// Simple way to attach js code to the canvas is by using a function
function sketchProc(processing) {
// Override draw function, by default it will be called 60 times per second
processing.draw = function() {
}
// erase background
processing.background(224);
public class clockfail2 extends PApplet {
// I think this might go in another document.
import processing.core.PApplet;
//the code for the rect/circle/ellipse app goes here.
};
var canvas = document.getElementById("canvas1");
// attaching the sketchProc function to the canvas
var p = new Processing(canvas, sketchProc);
// p.exit(); to detach it
</script>
<div style="height:0px;width:0px;overflow:hidden;"></div>
And lastly, I've tried putting this whole jazz in the background with the Robot class. Here's the link
http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Robot.html#Robot() .
And Just to test from square one here's my script trying to that.
public class Robot();
And here's the error I get:
"line 1:19: unexpected token: (
File /var/folders/69/69JcF82LEa8YZply920b0U+++TI/-Tmp-/build4356636896593188972.tmp/.java is missing"
(I'm using Mac OSX 10.5.8.)
I've spent probably about 40>= hours trying to do this whole project...if not more. I'm new to processing, so I consider struggling a way of learning...but at this point I'm really sick of looking at this, and I need answers.
Post-script (pun lulz) If anyone has a home remedy for headache/eye ache from staring at a computer screen...feel free to include it. :D
1