/ Published in: Groovy
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!usr/bin/env groovy //@+leo-ver=4-thin //@+node:lpt.20110228174854.1369:@thin XRobot.groovy //@@first //@@language java //@@lineending platform //@+doc // // 3/2/2011 // // file: XRobot.groovy // // Laurence Toenjes // // Created with Leo 4.6.3 final, build 2286, September 4, 2009 // http://webpages.charter.net/edreamleo/front.html // // I created this to help make groovysh act like the python -i option, // because I got tired of the extra typing of simulating the python // interpreter -i option . // // How to use: // youros> groovysh // // import XRobot // robot = XRobot.createRobot() // robot.sendString( '''// How now brown cow.''' ) // //@-doc //@@code //@+others //@+node:lpt.20110228174854.1370:imports import java.awt.event.KeyEvent //@-node:lpt.20110228174854.1370:imports //@+node:lpt.20110228174854.1373:class XRobot class XRobot { //@ @+others //@+node:lpt.20110228174854.1372:static def createRobot() //@ @+others //@+node:lpt.20110228174854.1374:c // // //@ @+others //@+node:lpt.20110228174854.1377:*** sendString keyList << keyInfoMap // has keys keyCode as int and shift as boolean } } } } } // end sendString //@-node:lpt.20110228174854.1377:*** sendString //@+node:lpt.20110228174854.1376:keyCodeClick } //@-node:lpt.20110228174854.1376:keyCodeClick //@+node:lpt.20110228174854.1375:keyCodeForLetter2 // based on http://gruimed.blogspot.com/2009/09/using-java-robot-to-type-text-strings.html // // returns a map with keys keyCode as int and shift as boolean int keyCode; case '~': case '!': case '@': case '#': case '$': case '%': case '^': case '&': case '*': case '(': case ')': case ':': case '_': case '+': case '|': // lpt mod // to handle some problem key strokes // special BEG case '"': shift = true case '\'': shift = false case '\n': // special END case '?': case '{': case '}': case '<': case '>': // lpt mod // handle letters and case shift = ch.isUpperCase(); } } // } //@-node:lpt.20110228174854.1375:keyCodeForLetter2 //@-others // } // end new Robot anon class return result // //@-node:lpt.20110228174854.1374:c //@-others } // end createRobot //@nonl //@-node:lpt.20110228174854.1372:static def createRobot() //@+node:lpt.20110228174854.1378:static def test1 // How // now // brown cow. '''; robot.sendString( testString ) return robot } //@nonl //@-node:lpt.20110228174854.1378:static def test1 //@-others } // end XRobot //@-node:lpt.20110228174854.1373:class XRobot //@-others //@-node:lpt.20110228174854.1369:@thin XRobot.groovy //@-leo