Advertisement
Fidycent

Untitled

Jul 11th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.89 KB | None | 0 0
  1. package javaapplication3;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.awt.event.ItemEvent;
  7. import java.awt.event.ItemListener;
  8. import java.io.*;
  9. import java.util.Scanner;
  10. import java.util.logging.Level;
  11. import java.util.logging.Logger;
  12. import javax.swing.*;
  13. import java.awt.AWTException;
  14. import java.awt.Robot;
  15. import java.awt.event.KeyEvent;
  16. import static java.awt.event.KeyEvent.*;
  17. public class Keyboard {
  18. private Robot robot;
  19. public static void main(String args[]) throws IOException {
  20. JFrame frame = new JFrame();
  21. JPanel panel = new JPanel();
  22. panel.setLayout(new FlowLayout());
  23. JButton button = new JButton();
  24. button.setText("2 Limenis");
  25. JCheckBox cb = new JCheckBox();
  26. panel.add(button);
  27. panel.add(cb);
  28. JCheckBox cb2 = new JCheckBox();
  29. panel.add(cb2);
  30. panel.setVisible(true);
  31. frame.add(panel);
  32. frame.setSize(500, 300);
  33. frame.setLocationRelativeTo(null);
  34. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  35. frame.setVisible(true);
  36. cb2.addItemListener(new ItemListener() {
  37. public void itemStateChanged(ItemEvent e) {
  38. int rez1 = 0;
  39. int rez2 = 0;
  40. int set = 0;
  41. boolean b1 = false;
  42. File file = new File("C:\\Program Files (x86)\\MTA San Andreas 1.5\\MTA\\logs\\console.log");
  43. String read;
  44. String line = "lohs";
  45. BufferedReader br2 = null;
  46. try {
  47. br2 = new BufferedReader (new FileReader(file));
  48. } catch (FileNotFoundException ex) {
  49. Logger.getLogger(Keyboard.class.getName()).log(Level.SEVERE, null, ex);
  50. }
  51. String strLine = null, tmp;
  52. while(e.getStateChange() == ItemEvent.SELECTED) {
  53. try {
  54. Thread.sleep(100);
  55. } catch (InterruptedException ex) {
  56. Logger.getLogger(Keyboard.class.getName()).log(Level.SEVERE, null, ex);
  57. }
  58. try {
  59. while ((tmp = br2.readLine()) != null)
  60. {
  61. strLine = tmp;
  62. } } catch (IOException ex) {
  63. Logger.getLogger(Keyboard.class.getName()).log(Level.SEVERE, null, ex);
  64. }
  65.  
  66. String lastLine = strLine;
  67.  
  68. System.out.println(lastLine);
  69.  
  70. String[] myList = lastLine.split(" ");
  71. int size = myList.length;
  72. if (size>=9){
  73. if(myList[4].equalsIgnoreCase("[PvP]") && myList[5].equalsIgnoreCase("Answer") && myList[6].equalsIgnoreCase("(use") ){
  74. System.out.println(lastLine);
  75. String s1 = myList[9];
  76. String s2 = myList[11];
  77. String s3 = myList[13];
  78. if (s1.startsWith("(") ){
  79. s1 = s1.substring(1);
  80. }
  81. if (s1.endsWith(")") ){
  82. int g = s1.length();
  83. g = g - 1;
  84. s1 = s1.substring(0,g);
  85. }
  86. if (s2.startsWith("(") ){
  87. s2 = s2.substring(1);
  88. }
  89. if (s2.endsWith(")") ){
  90. int g = s2.length();
  91. g = g - 1;
  92. s2 = s2.substring(0,g);
  93. }
  94. if (s3.startsWith("(") ){
  95. s3 = s3.substring(1);
  96. }
  97. if (s3.endsWith(")") ){
  98. int g = s3.length();
  99. g = g - 1;
  100. s3 = s3.substring(0,g);
  101. }
  102. int n1 = Integer.parseInt(s1);
  103. int n2 = Integer.parseInt(s2);
  104. int n3 = Integer.parseInt(s3);
  105. System.out.println(n1);
  106. System.out.println(n2);
  107. System.out.println(n3);
  108. if (myList[10].equalsIgnoreCase("-")) {
  109. rez1 = n1 - n2;
  110. System.out.println(rez1);
  111. }
  112. if (myList[10].equalsIgnoreCase("+")) {
  113. rez1 = n1 + n2;
  114. System.out.println(rez1);
  115. }
  116. if (myList[10].equalsIgnoreCase("*")) {
  117. rez1 = n1 * n2;
  118. System.out.println(rez1);
  119. }
  120. if (myList[10].equalsIgnoreCase(":")) {
  121. rez1 = n1 / n2;
  122. System.out.println(rez1);
  123. }
  124. if (myList[12].equalsIgnoreCase("-")) {
  125. rez2 = rez1 - n3;
  126. System.out.println(rez2);
  127. b1 = true;
  128. break;
  129. }
  130. if (myList[12].equalsIgnoreCase("+")) {
  131. rez2 = rez1 + n3;
  132. System.out.println(rez2);
  133. b1 = true;
  134. break;
  135. }
  136. if (myList[12].equalsIgnoreCase("*")) {
  137. rez2 = rez1 * n3;
  138. System.out.println(rez2);
  139. b1 = true;
  140. break;
  141. }
  142. if (myList[12].equalsIgnoreCase(":")) {
  143. rez2 = rez1 / n3;
  144. System.out.println(rez2);
  145. b1 = true;
  146. break;
  147. }
  148.  
  149. }
  150. }
  151.  
  152. }
  153. if(b1=true){
  154. JLabel label = new JLabel(String.valueOf(rez2));
  155. panel.add(label);
  156. frame.revalidate();
  157. frame.repaint();
  158. set = rez2;
  159. b1 = false;
  160.  
  161. }
  162. System.out.println("Lohs");
  163. Keyboard keyboard = null;
  164. try {
  165. keyboard = new Keyboard();
  166. } catch (AWTException ex) {
  167. Logger.getLogger(Keyboard.class.getName()).log(Level.SEVERE, null, ex);
  168. }
  169. keyboard.type(String.valueOf(rez2));
  170. keyboard.type(String.valueOf("\n"));
  171. }
  172.  
  173. });
  174. }
  175.  
  176.  
  177. public Keyboard() throws AWTException {
  178. this.robot = new Robot();
  179. }
  180.  
  181. public Keyboard(Robot robot) {
  182. this.robot = robot;
  183. }
  184.  
  185. public void type(CharSequence characters) {
  186. int length = characters.length();
  187. for (int i = 0; i < length; i++) {
  188. char character = characters.charAt(i);
  189. type(character);
  190. }
  191. }
  192.  
  193. public void type(char character) {
  194. switch (character) {
  195. case 'a': doType(VK_A); break;
  196. case 'b': doType(VK_B); break;
  197. case 'c': doType(VK_C); break;
  198. case 'd': doType(VK_D); break;
  199. case 'e': doType(VK_E); break;
  200. case 'f': doType(VK_F); break;
  201. case 'g': doType(VK_G); break;
  202. case 'h': doType(VK_H); break;
  203. case 'i': doType(VK_I); break;
  204. case 'j': doType(VK_J); break;
  205. case 'k': doType(VK_K); break;
  206. case 'l': doType(VK_L); break;
  207. case 'm': doType(VK_M); break;
  208. case 'n': doType(VK_N); break;
  209. case 'o': doType(VK_O); break;
  210. case 'p': doType(VK_P); break;
  211. case 'q': doType(VK_Q); break;
  212. case 'r': doType(VK_R); break;
  213. case 's': doType(VK_S); break;
  214. case 't': doType(VK_T); break;
  215. case 'u': doType(VK_U); break;
  216. case 'v': doType(VK_V); break;
  217. case 'w': doType(VK_W); break;
  218. case 'x': doType(VK_X); break;
  219. case 'y': doType(VK_Y); break;
  220. case 'z': doType(VK_Z); break;
  221. case 'A': doType(VK_SHIFT, VK_A); break;
  222. case 'B': doType(VK_SHIFT, VK_B); break;
  223. case 'C': doType(VK_SHIFT, VK_C); break;
  224. case 'D': doType(VK_SHIFT, VK_D); break;
  225. case 'E': doType(VK_SHIFT, VK_E); break;
  226. case 'F': doType(VK_SHIFT, VK_F); break;
  227. case 'G': doType(VK_SHIFT, VK_G); break;
  228. case 'H': doType(VK_SHIFT, VK_H); break;
  229. case 'I': doType(VK_SHIFT, VK_I); break;
  230. case 'J': doType(VK_SHIFT, VK_J); break;
  231. case 'K': doType(VK_SHIFT, VK_K); break;
  232. case 'L': doType(VK_SHIFT, VK_L); break;
  233. case 'M': doType(VK_SHIFT, VK_M); break;
  234. case 'N': doType(VK_SHIFT, VK_N); break;
  235. case 'O': doType(VK_SHIFT, VK_O); break;
  236. case 'P': doType(VK_SHIFT, VK_P); break;
  237. case 'Q': doType(VK_SHIFT, VK_Q); break;
  238. case 'R': doType(VK_SHIFT, VK_R); break;
  239. case 'S': doType(VK_SHIFT, VK_S); break;
  240. case 'T': doType(VK_SHIFT, VK_T); break;
  241. case 'U': doType(VK_SHIFT, VK_U); break;
  242. case 'V': doType(VK_SHIFT, VK_V); break;
  243. case 'W': doType(VK_SHIFT, VK_W); break;
  244. case 'X': doType(VK_SHIFT, VK_X); break;
  245. case 'Y': doType(VK_SHIFT, VK_Y); break;
  246. case 'Z': doType(VK_SHIFT, VK_Z); break;
  247. case '`': doType(VK_BACK_QUOTE); break;
  248. case '0': doType(VK_0); break;
  249. case '1': doType(VK_1); break;
  250. case '2': doType(VK_2); break;
  251. case '3': doType(VK_3); break;
  252. case '4': doType(VK_4); break;
  253. case '5': doType(VK_5); break;
  254. case '6': doType(VK_6); break;
  255. case '7': doType(VK_7); break;
  256. case '8': doType(VK_8); break;
  257. case '9': doType(VK_9); break;
  258. case '-': doType(VK_MINUS); break;
  259. case '=': doType(VK_EQUALS); break;
  260. case '~': doType(VK_SHIFT, VK_BACK_QUOTE); break;
  261. case '!': doType(VK_EXCLAMATION_MARK); break;
  262. case '@': doType(VK_AT); break;
  263. case '#': doType(VK_NUMBER_SIGN); break;
  264. case '$': doType(VK_DOLLAR); break;
  265. case '%': doType(VK_SHIFT, VK_5); break;
  266. case '^': doType(VK_CIRCUMFLEX); break;
  267. case '&': doType(VK_AMPERSAND); break;
  268. case '*': doType(VK_ASTERISK); break;
  269. case '(': doType(VK_LEFT_PARENTHESIS); break;
  270. case ')': doType(VK_RIGHT_PARENTHESIS); break;
  271. case '_': doType(VK_UNDERSCORE); break;
  272. case '+': doType(VK_PLUS); break;
  273. case '\t': doType(VK_TAB); break;
  274. case '\n': doType(VK_ENTER); break;
  275. case '[': doType(VK_OPEN_BRACKET); break;
  276. case ']': doType(VK_CLOSE_BRACKET); break;
  277. case '\\': doType(VK_BACK_SLASH); break;
  278. case '{': doType(VK_SHIFT, VK_OPEN_BRACKET); break;
  279. case '}': doType(VK_SHIFT, VK_CLOSE_BRACKET); break;
  280. case '|': doType(VK_SHIFT, VK_BACK_SLASH); break;
  281. case ';': doType(VK_SEMICOLON); break;
  282. case ':': doType(VK_COLON); break;
  283. case '\'': doType(VK_QUOTE); break;
  284. case '"': doType(VK_QUOTEDBL); break;
  285. case ',': doType(VK_COMMA); break;
  286. case '<': doType(VK_SHIFT, VK_COMMA); break;
  287. case '.': doType(VK_PERIOD); break;
  288. case '>': doType(VK_SHIFT, VK_PERIOD); break;
  289. case '/': doType(VK_SLASH); break;
  290. case '?': doType(VK_SHIFT, VK_SLASH); break;
  291. case ' ': doType(VK_SPACE); break;
  292. default:
  293. throw new IllegalArgumentException("Cannot type character " + character);
  294. }
  295. }
  296.  
  297. private void doType(int... keyCodes) {
  298. doType(keyCodes, 0, keyCodes.length);
  299. }
  300.  
  301. private void doType(int[] keyCodes, int offset, int length) {
  302. if (length == 0) {
  303. return;
  304. }
  305.  
  306. robot.keyPress(keyCodes[offset]);
  307. doType(keyCodes, offset + 1, length - 1);
  308. robot.keyRelease(keyCodes[offset]);
  309. }
  310.  
  311. private void keyPress(int VK_ENTER) {
  312. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  313. }
  314.  
  315. private void keyRelease(int VK_ENTER) {
  316. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  317. }
  318.  
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement