Hello,
I want to add a coin acceptor to my photobooth. I connected a coin acceptor trought the Ardiuno - Adruino counts pulses from acceptor and send coin value via serial port to pc. I tried to create simple program (with google help in Processing- it counts users credit and after pusshing the button it imitate key press Ctrl+# to print photos.
But there is a problem with photobooth software (NKRemote by Breezesys running on Win10) - when user push “PRINT” button it “press” Ctrl+# but the photobooth software isn´t active window and it does not respond. I need to switch windows (active application) after push “PRINT” button - something like Alt+TAB (push button -> change application to NKRemote -> press Ctrl+# -> change application to Processing). Is there any function to do this?
Thank You
import processing.serial.*;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
Serial port;
String input_data;
int coin_value;
int eol = 10;
int Credit=40;
int number_photos;
int picture_price=20;
int rectX, rectY;
int rectSize1 = 200;
int rectSize2 = 60;
color rectColor, baseColor;
color rectHighlight;
color currentColor;
boolean rectOver = false;
Robot robot;
void setup() {
size(300, 200);
surface.setAlwaysOnTop(true);
surface.setLocation(-2, -30);
println(Serial.list());
port = new Serial(this, Serial.list()[0], 9600);
port.clear();
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
exit();
}
rectColor = color(0);
rectHighlight = color(51);
rectX = 50;
rectY = 120;
baseColor = color(102);
currentColor = baseColor;
}
void draw() {
update(mouseX, mouseY);
background(currentColor);
if (rectOver) {
fill(rectHighlight);
} else {
fill(rectColor);
}
stroke(255);
rect(rectX, rectY, rectSize1, rectSize2);
while(port.available() > 0){
input_data = port.readStringUntil(eol);
if(input_data != null){
background(255);
coin_value = int(trim(input_data));
println(coin_value);
Credit = Credit + coin_value;
}
}
textSize(20);
fill(0, 0, 0);
text("Your credit=",10,50);
text(Credit,150,50);
text("I´ll print ",10,100);
number_photos = Credit/picture_price;
text(number_photos,140,100);
text("pc photos",180,100);
textSize(32);
fill(255, 255, 255);
text("PRINT",115,160);
}
void update(int x, int y) {
if ( overRect(rectX, rectY, rectSize1, rectSize2) ) {
rectOver = true;
} else {
rectOver = false;
}
}
void mousePressed() {
if (rectOver) {
if (number_photos == 1) {
robot.keyPress(17);
robot.keyPress(49);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(49);
Credit=0;
}
if (number_photos == 2) {
robot.keyPress(17);
robot.keyPress(50);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(50);
Credit=0;
}
if (number_photos == 3) {
robot.keyPress(17);
robot.keyPress(51);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(51);
Credit=0;
}
if (number_photos == 4) {
robot.keyPress(17);
robot.keyPress(52);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(52);
Credit=0;
}
if (number_photos == 5) {
robot.keyPress(17);
robot.keyPress(53);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(53);
Credit=0;
}
if (number_photos == 6) {
robot.keyPress(17);
robot.keyPress(54);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(54);
Credit=0;
}
if (number_photos == 7) {
robot.keyPress(17);
robot.keyPress(55);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(55);
Credit=0;
}
if (number_photos == 8) {
robot.keyPress(17);
robot.keyPress(56);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(56);
Credit=0;
}
if (number_photos == 9) {
robot.keyPress(17);
robot.keyPress(57);
robot.delay(100);
robot.keyRelease(17);
robot.keyRelease(57);
Credit=0;
}
}
}
boolean overRect(int x, int y, int width, int height) {
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}