Simulate input/Keyboard: Difference between revisions
(Tidy up language giving task specification) |
m (→{{header|Tcl}}) |
||
Line 13: | Line 13: | ||
{{libheader|Tk}}<br> |
{{libheader|Tk}}<br> |
||
This only works with windows created by Tk; it sends a single key “x” to the given window. |
This only works with windows created by Tk; it sends a single key “x” to the given window. |
||
<lang tcl> |
<lang tcl>set key "x" |
||
event generate $target <Key-$key></lang> |
|||
To send multiple keys, call repeatedly in order. |
To send multiple keys, call repeatedly in order. |
||
Alphabetic keys can be used directly as events, " " has to be mapped to "<space>". |
Alphabetic keys can be used directly as events, " " has to be mapped to "<space>". |
Revision as of 14:37, 2 June 2009
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Send simulated keystrokes to a GUI window. You should specify whether the target may be externally created (i.e., if the keystrokes are going to an application other than the application that is creating them).
AutoHotkey
target may be externally created. <lang AutoHotkey> run, cmd /k WinWait, ahk_class ConsoleWindowClass controlsend, ,hello console, ahk_class ConsoleWindowClass </lang>
Tcl
This only works with windows created by Tk; it sends a single key “x” to the given window. <lang tcl>set key "x" event generate $target <Key-$key></lang> To send multiple keys, call repeatedly in order. Alphabetic keys can be used directly as events, " " has to be mapped to "<space>". <lang Tcl>package require Tk pack [text .t] focus -force .t foreach c [split "hello world" ""] {
event generate .t [expr {$c eq " "?"<space>": $c}]
}</lang> Note also that the task on keyboard macros illustrates a very closely related method.