Simulate input/Keyboard: Difference between revisions
Content added Content deleted
(Added zkl) |
|||
Line 416: | Line 416: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
[[Category:Scala Implementations]] |
[[Category:Scala Implementations]]{{libheader|Scala}}<lang scala>import java.awt.Robot |
||
{{libheader|Scala}} |
|||
<lang scala>import java.awt.Robot |
|||
import java.awt.event.KeyEvent |
import java.awt.event.KeyEvent |
||
/** Keystrokes when this function is executed will go to whatever application has focus at the time. |
|||
* Special cases may need to be made for certain symbols, but most of |
|||
* the VK values in KeyEvent map to the ASCII values of characters. |
|||
*/ |
|||
object Keystrokes extends App { |
object Keystrokes extends App { |
||
def |
def keystroke(str: String) { |
||
val robot = new Robot() |
val robot = new Robot() |
||
for (ch <- str |
for (ch <- str) { |
||
if (Character.isUpperCase(ch)) { |
if (Character.isUpperCase(ch)) { |
||
robot.keyPress(KeyEvent.VK_SHIFT) |
robot.keyPress(KeyEvent.VK_SHIFT) |
||
robot.keyPress(ch) |
robot.keyPress(ch) |
||
robot.keyRelease(ch) |
robot.keyRelease(ch) |
||
robot.keyRelease(KeyEvent.VK_SHIFT) |
robot.keyRelease(KeyEvent.VK_SHIFT) |
||
} else { |
} else { |
||
val upCh = Character.toUpperCase(ch) |
val upCh = Character.toUpperCase(ch) |
||
robot.keyPress(upCh) |
robot.keyPress(upCh) |
||
robot.keyRelease(upCh) |
robot.keyRelease(upCh) |
||
} |
} |
||
} |
} |
||
} |
} |
||
keystroke(args(0)) |
|||
}</lang> |
}</lang> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |