-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckout.java
More file actions
103 lines (87 loc) · 3.08 KB
/
Checkout.java
File metadata and controls
103 lines (87 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;
/**
* Automates saving VitalSource ebooks as PDFs.
* @author Jayden Weaver
*
*/
public class Checkout {
public static void main(String args[]){
int pageNumber = Integer.parseInt(args[0]);
int totalPages = Integer.parseInt(args[1]);
int pagesToPrint = Integer.parseInt(args[2]);
int pdfNumber = 0;
Clipboard clipboard;
StringSelection stringSelection;
try {
System.out.println("Select the VitalSource Bookshelf ebook Window within the next six seconds.");
TimeUnit.SECONDS.sleep(6);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
while(pageNumber < totalPages){
//Prepare page number
stringSelection = new StringSelection("" + pageNumber);
//Update page number
pageNumber += pagesToPrint;
//Add page number to clipboard to CTRL + V later.
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, stringSelection);
Robot robot = new Robot(); //beep boop
//CTRL + P
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_P);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_P);
//Tab to the page box and delete everything.
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_DELETE);
robot.keyRelease(KeyEvent.VK_DELETE);
robot.keyPress(KeyEvent.VK_DELETE);
robot.keyRelease(KeyEvent.VK_DELETE);
robot.keyPress(KeyEvent.VK_DELETE);
robot.keyRelease(KeyEvent.VK_DELETE);
robot.keyPress(KeyEvent.VK_DELETE);
robot.keyRelease(KeyEvent.VK_DELETE);
//Enter page number with CTRL + V
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
//Tab to update other box
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
//Hit enter on all the boxes
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
TimeUnit.SECONDS.sleep(2);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
//Paste PDF number to save without overwriting
stringSelection = new StringSelection("" + pdfNumber);
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, stringSelection);
TimeUnit.SECONDS.wait(2);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
//Wait 1 minute to save PDF. May take longer, further testing is needed.
TimeUnit.MINUTES.sleep(1);
}
} catch (AWTException | InterruptedException e) {
e.printStackTrace();
}
}
}