@@ -42,41 +42,44 @@ public static void initConstants() {
4242 @ Override
4343 public void init () {
4444 initConstants ();
45- initialize ();
46-
47- Functions .set ("click" , convertFunction (robot ::click ));
48- Functions .set ("delay" , convertFunction (awtRobot ::delay ));
49- Functions .set ("setAutoDelay" , convertFunction (awtRobot ::setAutoDelay ));
50- Functions .set ("keyPress" , convertFunction (awtRobot ::keyPress ));
51- Functions .set ("keyRelease" , convertFunction (awtRobot ::keyRelease ));
52- Functions .set ("mousePress" , convertFunction (awtRobot ::mousePress ));
53- Functions .set ("mouseRelease" , convertFunction (awtRobot ::mouseRelease ));
54- Functions .set ("mouseWheel" , convertFunction (awtRobot ::mouseWheel ));
55- Functions .set ("mouseMove" , (args ) -> {
56- Arguments .check (2 , args .length );
57- try {
58- awtRobot .mouseMove (args [0 ].asInt (), args [1 ].asInt ());
59- } catch (IllegalArgumentException iae ) { }
60- return NumberValue .ZERO ;
61- });
62- Functions .set ("typeText" , (args ) -> {
63- Arguments .check (1 , args .length );
64- try {
65- typeText (args [0 ].asString ());
66- } catch (IllegalArgumentException iae ) { }
67- return NumberValue .ZERO ;
68- });
69- Functions .set ("toClipboard" , new robot_toclipboard ());
70- Functions .set ("fromClipboard" , new robot_fromclipboard ());
45+ boolean isRobotInitialized = initialize ();
46+ if (isRobotInitialized ) {
47+ Functions .set ("click" , convertFunction (robot ::click ));
48+ Functions .set ("delay" , convertFunction (awtRobot ::delay ));
49+ Functions .set ("setAutoDelay" , convertFunction (awtRobot ::setAutoDelay ));
50+ Functions .set ("keyPress" , convertFunction (awtRobot ::keyPress ));
51+ Functions .set ("keyRelease" , convertFunction (awtRobot ::keyRelease ));
52+ Functions .set ("mousePress" , convertFunction (awtRobot ::mousePress ));
53+ Functions .set ("mouseRelease" , convertFunction (awtRobot ::mouseRelease ));
54+ Functions .set ("mouseWheel" , convertFunction (awtRobot ::mouseWheel ));
55+ Functions .set ("mouseMove" , (args ) -> {
56+ Arguments .check (2 , args .length );
57+ try {
58+ awtRobot .mouseMove (args [0 ].asInt (), args [1 ].asInt ());
59+ } catch (IllegalArgumentException iae ) { }
60+ return NumberValue .ZERO ;
61+ });
62+ Functions .set ("typeText" , (args ) -> {
63+ Arguments .check (1 , args .length );
64+ try {
65+ typeText (args [0 ].asString ());
66+ } catch (IllegalArgumentException iae ) { }
67+ return NumberValue .ZERO ;
68+ });
69+ Functions .set ("toClipboard" , new robot_toclipboard ());
70+ Functions .set ("fromClipboard" , new robot_fromclipboard ());
71+ }
7172 Functions .set ("execProcess" , new robot_exec (robot_exec .Mode .EXEC ));
7273 Functions .set ("execProcessAndWait" , new robot_exec (robot_exec .Mode .EXEC_AND_WAIT ));
7374 }
7475
75- private static void initialize () {
76+ private static boolean initialize () {
7677 try {
7778 awtRobot = new Robot ();
79+ return true ;
7880 } catch (AWTException awte ) {
79- throw new RuntimeException ("Unable to create robot instance" , awte );
81+ //throw new RuntimeException("Unable to create robot instance", awte);
82+ return false ;
8083 }
8184 }
8285
0 commit comments