Commit 2fcc314e authored by gaa721's avatar gaa721
Browse files

updated System b

parent 6869817a
boolean isPayingAttention()
{
long now = System.nanoTime();
if (windowingScore()>50&&(attentionScore()>50||now-lastKeyInput<1000000000||now-lastMouseInput<1000000000))
{
return true;
}
else
{
return false;
}
}
int windowingScore()
{
if (wasMinimized)
{
return 0;
}
if (foreground)
{
return 100;
}
if (!obscured)
{
return 80;
}
else
{
return 20;
}
}
int attentionScore()
{
long now = System.nanoTime();
if (faces.length>0)
lastFace = now;
if (motionDetected)
lastMotion = now;
if (faces.length>0&&motionDetected)
{
return 100;
}
else if (faces.length>0&&!motionDetected)
{
return 80;
}
else if (now-lastFace<1000000000&&motionDetected)
{
return 60;
}
else if (now-lastFace<1000000000&&now-lastFace<1000000000)
{
return 51;
}
else
{
return 0;
}
}
boolean isMinimized(HWND window)
{
WINDOWINFO info = new WINDOWINFO();
User32.INSTANCE.GetWindowInfo(window, info);
if ((info.dwStyle & WS_ICONIC) == WS_ICONIC) {
return true;
}
else
{
return false;
}
}
void onKeyInput()
{
lastKeyInput = System.nanoTime();
}
void onMouseInput()
{
lastMouseInput = System.nanoTime();
}
void captureEvent(Capture c) {
c.read();
}
boolean hasWhite(PImage image)
{
for (int i = 0; i< image.pixels.length; i++)
{
if (image.pixels[i]==color(255, 255, 255))
return true;
}
return false;
}
boolean isObscured()
{
HWND currWindow = User32.INSTANCE.GetForegroundWindow();
int i = 0;
//get all the size/positions of windows above the window of interest
while (i<1000)
{
/*if(stateChanged)
{
char[] asdf = new char[200];
User32.INSTANCE.GetWindowText(currWindow, asdf, 200);
println(Native.toString(asdf));
}*/
RECT currRect = new RECT();
User32.INSTANCE.GetWindowRect(currWindow, currRect);
User32.INSTANCE.GetWindowText(currWindow, windowText, strBuffSize);
//see we are at the window of interest
//if we are, save the size/position and exit search
if (Native.toString(windowText).compareTo(windowTitle) == 0)
{
rectOfInterest = currRect;
if (currWindow!=null)
windowOfInterest = currWindow;
break;
}
else
{
//add positions/size of current window and get next window
aboveWindows.add(currRect);
currWindow = User32.INSTANCE.GetWindow(currWindow, new DWORD(User32.GW_HWNDNEXT));
i++;
}
}
boolean r = checkOverlap();
aboveWindows.clear();
return r;
}
boolean checkOverlap()
{
//compare above window positions to window of interest to see if they overlap
for (RECT currRect : aboveWindows)
{
//four cases of non overlap
if (rectOfInterest.left > currRect.right) //completely to the right
{
continue;
}
if (rectOfInterest.right < currRect.left) //completely to the left
{
continue;
}
if (rectOfInterest.top > currRect.bottom) //completely below
{
continue;
}
if (rectOfInterest.bottom < currRect.top) //completely above
{
continue;
}
return true;
}
return false;
}
public class InputReceiver implements NativeKeyListener, NativeMouseInputListener
{
AttentionDrawing sketch;
InputReceiver(AttentionDrawing s) {
try {
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
//Add the appropriate listeners for the example object.
GlobalScreen.addNativeMouseListener(this);
GlobalScreen.addNativeMouseMotionListener(this);
GlobalScreen.addNativeKeyListener(this);
sketch = s;
}
void nativeKeyPressed(NativeKeyEvent e) {
sketch.onKeyInput();
}
void nativeKeyReleased(NativeKeyEvent e) {
sketch.onKeyInput();
}
void nativeKeyTyped(NativeKeyEvent e) {
sketch.onKeyInput();
}
void nativeMouseClicked(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMousePressed(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMouseReleased(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMouseMoved(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMouseDragged(NativeMouseEvent e) {
sketch.onMouseInput();
}
}
boolean isPayingAttention()
{
long now = System.nanoTime();
if (windowingScore()>50&&(attentionScore()>50||now-lastKeyInput<1000000000||now-lastMouseInput<1000000000))
{
return true;
}
else
{
return false;
}
}
int windowingScore()
{
if (wasMinimized)
{
return 0;
}
if (foreground)
{
return 100;
}
if (!obscured)
{
return 80;
}
else
{
return 20;
}
}
int attentionScore()
{
long now = System.nanoTime();
if (faces.length>0)
lastFace = now;
if (motionDetected)
lastMotion = now;
if (faces.length>0&&motionDetected)
{
return 100;
}
else if (faces.length>0&&!motionDetected)
{
return 80;
}
else if (now-lastFace<1000000000&&motionDetected)
{
return 60;
}
else if (now-lastFace<1000000000&&now-lastFace<1000000000)
{
return 51;
}
else
{
return 0;
}
}
boolean isMinimized(HWND window)
{
WINDOWINFO info = new WINDOWINFO();
User32.INSTANCE.GetWindowInfo(window, info);
if ((info.dwStyle & WS_ICONIC) == WS_ICONIC) {
return true;
}
else
{
return false;
}
}
void onKeyInput()
{
lastKeyInput = System.nanoTime();
}
void onMouseInput()
{
lastMouseInput = System.nanoTime();
}
//void captureEvent(Capture c) {
// c.read();
//}
boolean hasWhite(PImage image)
{
for (int i = 0; i< image.pixels.length; i++)
{
if (image.pixels[i]==color(255, 255, 255))
return true;
}
return false;
}
boolean isObscured()
{
HWND currWindow = User32.INSTANCE.GetForegroundWindow();
int i = 0;
//get all the size/positions of windows above the window of interest
while (i<1000)
{
/*if(stateChanged)
{
char[] asdf = new char[200];
User32.INSTANCE.GetWindowText(currWindow, asdf, 200);
println(Native.toString(asdf));
}*/
RECT currRect = new RECT();
User32.INSTANCE.GetWindowRect(currWindow, currRect);
User32.INSTANCE.GetWindowText(currWindow, windowText, strBuffSize);
//see we are at the window of interest
//if we are, save the size/position and exit search
if (Native.toString(windowText).compareTo(windowTitle) == 0)
{
rectOfInterest = currRect;
if (currWindow!=null)
windowOfInterest = currWindow;
break;
}
else
{
//add positions/size of current window and get next window
aboveWindows.add(currRect);
currWindow = User32.INSTANCE.GetWindow(currWindow, new DWORD(User32.GW_HWNDNEXT));
i++;
}
}
boolean r = checkOverlap();
aboveWindows.clear();
return r;
}
boolean checkOverlap()
{
//compare above window positions to window of interest to see if they overlap
for (RECT currRect : aboveWindows)
{
//four cases of non overlap
if (rectOfInterest.left > currRect.right) //completely to the right
{
continue;
}
if (rectOfInterest.right < currRect.left) //completely to the left
{
continue;
}
if (rectOfInterest.top > currRect.bottom) //completely below
{
continue;
}
if (rectOfInterest.bottom < currRect.top) //completely above
{
continue;
}
return true;
}
return false;
}
public class InputReceiver implements NativeKeyListener, NativeMouseInputListener
{
AttentionDrawing sketch;
InputReceiver(AttentionDrawing s) {
try {
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
//Add the appropriate listeners for the example object.
GlobalScreen.addNativeMouseListener(this);
GlobalScreen.addNativeMouseMotionListener(this);
GlobalScreen.addNativeKeyListener(this);
sketch = s;
}
void nativeKeyPressed(NativeKeyEvent e) {
sketch.onKeyInput();
}
void nativeKeyReleased(NativeKeyEvent e) {
sketch.onKeyInput();
}
void nativeKeyTyped(NativeKeyEvent e) {
sketch.onKeyInput();
}
void nativeMouseClicked(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMousePressed(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMouseReleased(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMouseMoved(NativeMouseEvent e) {
sketch.onMouseInput();
}
void nativeMouseDragged(NativeMouseEvent e) {
sketch.onMouseInput();
}
}
\ No newline at end of file
import java.io.*;
import java.util.ArrayList;
class Question implements Serializable
{
String type;
String question;
Rectangle answer;
public Question(String type, String quest, Rectangle ans)
{
this.type = type;
this.question = quest;
this.answer = ans;
}
public Question( String type, String quest)
{
this.type = type;
this.question = quest;
}
//
// public Question(String quest)
// {
// this.question = quest;
// this.answer = ans;
// }
public String getQuestion()
{
return question;
}
public void setQuestion(String quest)
{
this.question = quest;
}
public void setQuestion (Rectangle ans)
{
this.answer = ans;
}
}
import java.io.*;
import java.util.ArrayList;
class Question implements Serializable
{
String quest;
public Question( String quest)
{
this.quest = quest;
}
public String getQuestion()
{
return quest;
}
public void setQuestion(String quest)
{
this.quest = quest;
}
public void presentQuestion()
{
}
public String getType()
{
return "";
}
public Rectangle getAnswer()
{
return null;
}
}
\ No newline at end of file
Question [][] questionandanswers = {
{
new Question( "Rectangle", "When you were not attentive, something was drawn. Mark that portion.", new Rectangle(398.0, 234.0, 236.0, 347.0)),
new Question( "Rectangle", "When you were not attentive, many lines were drawn. Mark the most recent line.", new Rectangle(896.0, 642.0, 847.0, 689.0)),
new Question( "Rectangle", "When you were not attentive, circle was moved. Mark the initial position of that circle.", new Rectangle(1127.0, 131.0, 1021.0, 234.0)),
new Question( "Rectangle", "When you were not attentive, two lines were drawn. Mark the line which was drawn first.", new Rectangle(1109.0, 782.0, 1038.0, 859.0)),
new Question( "Rectangle", "When you were not attentive, one the circles was deleted. Mark the position where was the circle and how big was it? ", new Rectangle(409.0, 504.0, 445.0, 538.0))
}
,
{
new Question( "Rectangle", "When you were not attentive, one the Rectangles was deleted. Mark the position where was the Rectangle and how big was it?", new Rectangle(750.0, 504.0, 850.0, 602.0)),
new Question( "Rectangle", "When you were not attentive, something was drawn. Mark that Portion.", new Rectangle(1566.0, 153.0, 1659.0, 79.0)),
new Question( "Rectangle", "When you were not attentive, Rectangle was moved. Mark the initial position and size of the Rectangle.", new Rectangle(228.0, 778.0, 171.0, 723.0)),
new Question( "Rectangle", "When you were not attentive, many lines were drawn. Mark the line which was drawn last.", new Rectangle(1506.0, 825.0, 1538.0, 882.0)),
new Question( "Rectangle", "When you were not attentive, two lines were drawn. Mark the line which was drawn first. ", new Rectangle(28.0, 848.0, 110.0, 791.0))
}
,
{
new Question( "Rectangle", "When you were not attentive, two lines were drawn. Mark the line which was drawn first.", new Rectangle(292.0, 141.0, 357.0, 211.0)),
new Question( "Rectangle", "When you were not attentive, circle was moved. Mark the initial position and size of the Circle.", new Rectangle(886.0, 551.0, 969.0, 633.0)),
new Question( "Rectangle", "When you were not attentive, one the circles was deleted. Mark the position where was the circle and how big was it?", new Rectangle(66.0, 480.0, 159.0, 375.0)),
new Question( "Rectangle", "When you were not attentive, something was drawn. Mark the bigger portion.", new Rectangle(1434.0, 146.0, 1490.0, 222.0)),
new Question( "Rectangle", "When you were not attentive, some lines were drawn. Mark the line drawn last.", new Rectangle(1483.0, 171.0, 1490.0, 204.0))
}
,
{
new Question( "Rectangle", "When you were not attentive, something was drawn. Mark that portion. ", new Rectangle(251.0, 334.0, 174.0, 441.0)),
new Question( "Rectangle", "When you were not attentive, circle was moved. Mark the initial position and size of the Circle. ", new Rectangle(242.0, 400.0, 298.0, 457.0)),
new Question( "Rectangle", "When you were not attentive, one the circles were deleted. Mark the position where was the circle and how big was it?", new Rectangle(504.0, 558.0, 573.0, 621.0)),
new Question( "Rectangle", "When you were not attentive, some lines were drawn. Mark the line drawn first.", new Rectangle(1554.0, 241.0, 1600.0, 267.0)),
new Question( "Rectangle", "When you were not attentive, a big line was drawn. Mark the starting point of the line.", new Rectangle(1006.0, 117.0, 1046.0, 140.0))
}
,
};
Question [][] questionandanswers = {
{
new RectangleQuestion( "When you were not attentive, something was drawn. Mark that portion.", new Rectangle(245.0, 245.0, 359.0, 330.0)),
new RectangleQuestion( "When you were not attentive, many lines were drawn. Mark the most recent line.", new Rectangle(365.0, 609.0, 398.0, 655.0)),
new RectangleQuestion( "When you were not attentive, circle was moved. Mark the initial position of that circle.", new Rectangle(1033.0, 179.0, 1138.0, 275.0)),
new RectangleQuestion( "When you were not attentive, two lines were drawn. Mark the line which was drawn first.", new Rectangle(1124.0, 419.0, 1237.0, 348.0)),
new RectangleQuestion( "When you were not attentive, one the circles was deleted. Mark the position where was the circle and how big was it? ", new Rectangle(179.0, 684.0, 266.0, 761.0))
}
,
{
new RectangleQuestion( "When you were not attentive, one the Rectangles was deleted. Mark the position where was the Rectangle and how big was it?", new Rectangle(652.0, 514.0, 687.0, 547.0)),
new RectangleQuestion( "When you were not attentive, something was drawn. Mark that Portion.", new Rectangle(552.0, 160.0, 666.0, 55.0)),
new RectangleQuestion( "When you were not attentive, Rectangle was moved. Mark the initial position and size of the Rectangle.", new Rectangle(690.0, 423.0, 630.0, 368.0)),
new RectangleQuestion( "When you were not attentive, many lines were drawn. Mark the line which was drawn last.", new Rectangle(518.0, 400.0, 570.0, 475.0)),
new RectangleQuestion( "When you were not attentive, two lines were drawn. Mark the line which was drawn first. ", new Rectangle(29.0, 196.0, 107.0, 123.0))
}
,
{
new RectangleQuestion( "When you were not attentive, two lines were drawn. Mark the line which was drawn first.", new Rectangle(365.0, 300.0, 499.0, 336.0)),
new RectangleQuestion( "When you were not attentive, circle was moved. Mark the initial position and size of the Circle.", new Rectangle(382.0, 173.0, 482.0, 272.0)),
new Rectan