all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
2
Task/Simulate-input-Keyboard/0DESCRIPTION
Normal file
2
Task/Simulate-input-Keyboard/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{{Omit From|Modula-3}}
|
||||
Send simulated keystrokes to a GUI window, or terminal. 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).
|
||||
4
Task/Simulate-input-Keyboard/1META.yaml
Normal file
4
Task/Simulate-input-Keyboard/1META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Testing
|
||||
note: GUI
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
run, cmd /k
|
||||
WinWait, ahk_class ConsoleWindowClass
|
||||
controlsend, ,hello console, ahk_class ConsoleWindowClass
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Run("notepad")
|
||||
WinWaitActive("Untitled - Notepad")
|
||||
Send("The answer is 42")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
$name="type your name here"
|
||||
$name = InputBox("Name","Your name please ?",$name)
|
||||
MsgBox(0,"Name","Your name is: "&$name)
|
||||
114
Task/Simulate-input-Keyboard/C/simulate-input-keyboard.c
Normal file
114
Task/Simulate-input-Keyboard/C/simulate-input-keyboard.c
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Display *dpy;
|
||||
Window win;
|
||||
GC gc;
|
||||
int scr;
|
||||
Atom WM_DELETE_WINDOW;
|
||||
XEvent ev;
|
||||
XEvent ev2;
|
||||
KeySym keysym;
|
||||
int loop;
|
||||
|
||||
/* open connection with the server */
|
||||
dpy = XOpenDisplay(NULL);
|
||||
if (dpy == NULL) {
|
||||
fputs("Cannot open display", stderr);
|
||||
exit(1);
|
||||
}
|
||||
scr = XDefaultScreen(dpy);
|
||||
|
||||
/* create window */
|
||||
win = XCreateSimpleWindow(dpy,
|
||||
XRootWindow(dpy, scr),
|
||||
/* x, y, width, height, border_width */
|
||||
10, 10, 300, 200, 1,
|
||||
/* border, background */
|
||||
XBlackPixel(dpy, scr), XWhitePixel(dpy, scr));
|
||||
|
||||
/* set window name */
|
||||
XStoreName(dpy, win, argv[0]);
|
||||
|
||||
/* select kind of events we are interested in */
|
||||
XSelectInput(dpy, win, ExposureMask | KeyPressMask | ButtonPressMask);
|
||||
|
||||
/* map (show) the window */
|
||||
XMapWindow(dpy, win);
|
||||
XFlush(dpy);
|
||||
|
||||
/* default graphics context */
|
||||
gc = XDefaultGC(dpy, scr);
|
||||
|
||||
/* connect the close button in the window handle */
|
||||
WM_DELETE_WINDOW = XInternAtom(dpy, "WM_DELETE_WINDOW", True);
|
||||
XSetWMProtocols(dpy, win, &WM_DELETE_WINDOW, 1);
|
||||
|
||||
/* event loop */
|
||||
loop = 1;
|
||||
while (loop) {
|
||||
XNextEvent(dpy, &ev);
|
||||
switch (ev.type)
|
||||
{
|
||||
case Expose:
|
||||
/* draw or redraw the window */
|
||||
{
|
||||
char msg1[] = "Clic in the window to generate";
|
||||
char msg2[] = "a key press event";
|
||||
XDrawString(dpy, win, gc, 10, 20, msg1, sizeof(msg1)-1);
|
||||
XDrawString(dpy, win, gc, 10, 35, msg2, sizeof(msg2)-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
puts("ButtonPress event received");
|
||||
/*
|
||||
printf("> button (x,y) : %d %d\n",
|
||||
ev.xbutton.x,
|
||||
ev.xbutton.y);
|
||||
*/
|
||||
ev2.type = KeyPress;
|
||||
ev2.xkey.state = ShiftMask;
|
||||
ev2.xkey.keycode = 24 + (rand() % 33);
|
||||
ev2.xkey.same_screen = True;
|
||||
XSendEvent(dpy, win, True/*propagate*/, KeyPressMask, &ev2);
|
||||
break;
|
||||
|
||||
case ClientMessage:
|
||||
/* delete window event */
|
||||
if (ev.xclient.data.l[0] == WM_DELETE_WINDOW)
|
||||
loop = 0;
|
||||
break;
|
||||
|
||||
case KeyPress:
|
||||
/* handle key press */
|
||||
puts("KeyPress event received");
|
||||
printf("> keycode: %d\n", ev.xkey.keycode);
|
||||
/* exit if q or escape are pressed */
|
||||
keysym = XLookupKeysym(&(ev.xkey), 0);
|
||||
if (keysym == XK_q ||
|
||||
keysym == XK_Escape) {
|
||||
loop = 0;
|
||||
} else {
|
||||
char buffer[] = " ";
|
||||
int nchars = XLookupString(
|
||||
&(ev.xkey),
|
||||
buffer,
|
||||
2, /* buffer size */
|
||||
&keysym,
|
||||
NULL );
|
||||
if (nchars == 1)
|
||||
printf("> Key '%c' pressed\n", buffer[0]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
XDestroyWindow(dpy, win);
|
||||
/* close connection to server */
|
||||
XCloseDisplay(dpy);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
(import java.awt.Robot)
|
||||
(import java.awt.KeyEvent)
|
||||
(defn keytype [str]
|
||||
(let [robot (new Robot)]
|
||||
(doseq [ch str]
|
||||
(if (Character/isUpperCase ch)
|
||||
(doto robot
|
||||
(.keyPress (. KeyEvent VK_SHIFT))
|
||||
(.keyPress (int ch))
|
||||
(.keyRelease (int ch))
|
||||
(.keyRelease (. KeyEvent VK_SHIFT)))
|
||||
(let [upCh (Character/toUpperCase ch)]
|
||||
(doto robot
|
||||
(.keyPress (int upCh))
|
||||
(.keyRelease (int upCh))))))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
Start,Programs,Accessories,Notepad,Textbox,Type:Hello World[pling]
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import java.awt.Robot
|
||||
public static void type(String str){
|
||||
Robot robot = new Robot();
|
||||
for(char ch:str.toCharArray()){
|
||||
if(Character.isUpperCase(ch)){
|
||||
robot.keyPress(KeyEvent.VK_SHIFT);
|
||||
robot.keyPress((int)ch);
|
||||
robot.keyRelease((int)ch);
|
||||
robot.keyRelease(KeyEvent.VK_SHIFT);
|
||||
}else{
|
||||
char upCh = Character.toUpperCase(ch);
|
||||
robot.keyPress((int)upCh);
|
||||
robot.keyRelease((int)upCh);
|
||||
}
|
||||
}
|
||||
}
|
||||
105
Task/Simulate-input-Keyboard/OCaml/simulate-input-keyboard.ocaml
Normal file
105
Task/Simulate-input-Keyboard/OCaml/simulate-input-keyboard.ocaml
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
open Xlib
|
||||
|
||||
let () =
|
||||
(* open connection with the server *)
|
||||
let d = xOpenDisplay "" in
|
||||
let s = xDefaultScreen d in
|
||||
|
||||
Random.self_init();
|
||||
|
||||
(* create window *)
|
||||
let w = xCreateSimpleWindow d (xRootWindow d s) 10 10 300 200 1
|
||||
(xBlackPixel d s) (xWhitePixel d s) in
|
||||
|
||||
(* set window name *)
|
||||
xStoreName d w Sys.argv.(0);
|
||||
|
||||
(* select kind of events we are interested in *)
|
||||
xSelectInput d w [ExposureMask; KeyPressMask; ButtonPressMask];
|
||||
|
||||
(* map (show) the window *)
|
||||
xMapWindow d w;
|
||||
xFlush d;
|
||||
|
||||
let dbl = w in
|
||||
let gc = xDefaultGC d s in
|
||||
|
||||
(* connect the close button in the window handle *)
|
||||
let wm_delete_window = xInternAtom d "WM_DELETE_WINDOW" true in
|
||||
xSetWMProtocols d w wm_delete_window 1;
|
||||
|
||||
(* event loop *)
|
||||
let e = new_xEvent() in
|
||||
try while true do
|
||||
xNextEvent d e;
|
||||
|
||||
(* draw or redraw the window *)
|
||||
match xEventKind e with
|
||||
| XExposeEvent _ ->
|
||||
xDrawString d dbl gc 10 20 "Clic in the window to generate";
|
||||
xDrawString d dbl gc 10 35 "a key press event";
|
||||
|
||||
| XButtonPressedEvent event ->
|
||||
let dat = xButtonEvent_datas event in
|
||||
(*
|
||||
Printf.printf "button x,y : %d %d\n%!"
|
||||
dat.button_x
|
||||
dat.button_y;
|
||||
*)
|
||||
let xKeyEvent_contents = {
|
||||
key_serial = dat.button_serial;
|
||||
key_send_event = dat.button_send_event;
|
||||
key_display = dat.button_display;
|
||||
key_window = dat.button_window;
|
||||
key_root = dat.button_root;
|
||||
key_subwindow = dat.button_subwindow;
|
||||
key_time = dat.button_time;
|
||||
key_x = dat.button_x;
|
||||
key_y = dat.button_y;
|
||||
key_x_root = dat.button_x_root;
|
||||
key_y_root = dat.button_y_root;
|
||||
|
||||
key_state = [ShiftMask];
|
||||
key_keycode = (24 + Random.int 33);
|
||||
key_same_screen = true;
|
||||
} in
|
||||
let propagate = true in
|
||||
let event_mask = KeyPressMask in
|
||||
xSendEvent d w propagate event_mask (XKeyPressedEvCnt xKeyEvent_contents);
|
||||
|
||||
(* delete window event *)
|
||||
| XClientMessageEvent xclient ->
|
||||
let atom = xEvent_xclient_data xclient in
|
||||
if atom = wm_delete_window then
|
||||
raise Exit
|
||||
|
||||
(* handle key press *)
|
||||
| XKeyPressedEvent event ->
|
||||
print_endline "Key Pressed Event";
|
||||
begin
|
||||
let d = xKeyEvent_datas event in
|
||||
Printf.printf "keycode: %d\n%!" d.key_keycode;
|
||||
end;
|
||||
(* exit if q or escape are pressed *)
|
||||
let keysym = xLookupKeysym event 0 in
|
||||
if keysym = Keysym.xK_q ||
|
||||
keysym = Keysym.xK_Escape then
|
||||
raise Exit
|
||||
else
|
||||
let printable, c =
|
||||
let buf = " " in
|
||||
let n, _ = xLookupString event buf in
|
||||
if (n = 1)
|
||||
then (true, buf.[0])
|
||||
else (false, '\000')
|
||||
in
|
||||
if printable then
|
||||
Printf.printf "Key '%c' pressed\n%!" c;
|
||||
|
||||
| _ -> ()
|
||||
done with
|
||||
| Exit ->
|
||||
xDestroyWindow d w;
|
||||
(* close connection to server *)
|
||||
xCloseDisplay d;
|
||||
;;
|
||||
14
Task/Simulate-input-Keyboard/Oz/simulate-input-keyboard.oz
Normal file
14
Task/Simulate-input-Keyboard/Oz/simulate-input-keyboard.oz
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
declare
|
||||
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']}
|
||||
Entry
|
||||
Window = {QTk.build td(entry(handle:Entry))}
|
||||
in
|
||||
{Window show}
|
||||
{Entry getFocus(force:true)}
|
||||
|
||||
for C in "Hello, world!" do
|
||||
Key = if C == 32 then "<space>" else [C] end
|
||||
in
|
||||
{Delay 100}
|
||||
{Tk.send event(generate Entry Key)}
|
||||
end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
$target = "/dev/pts/51";
|
||||
### How to get the correct value for $TIOCSTI is discussed here : http://www.perlmonks.org/?node_id=10920
|
||||
$TIOCSTI = 0x5412 ;
|
||||
open(TTY,">$target") or die "cannot open $target" ;
|
||||
$b="sleep 99334 &\015";
|
||||
@c=split("",$b);
|
||||
sleep(2);
|
||||
foreach $a ( @c ) { ioctl(TTY,$TIOCSTI,$a); select(undef,undef,undef,0.1);} ;
|
||||
print "DONE\n";
|
||||
|
|
@ -0,0 +1 @@
|
|||
SendKeys("Hello, how are you?\n");
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
(load "@lib/http.l" "@lib/scrape.l")
|
||||
|
||||
# Connect to the demo app at http://7fach.de/8080
|
||||
(scrape "7fach.de" 80 "8080")
|
||||
|
||||
# Log in
|
||||
(expect "'admin' logged in"
|
||||
(enter 3 "admin") # Enter user name into 3rd field
|
||||
(enter 4 "admin") # Enter password into 4th field
|
||||
(press "login") ) # Press the "login" button
|
||||
|
||||
(click "Items") # Open "Items" dialog
|
||||
(click "Spare Part") # Click on "Spare Part" article
|
||||
(prinl (value 8)) # Print the price (12.50)
|
||||
(click "logout") # Log out
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
If AW_WinActivate("Calc")
|
||||
AW_SendKeys("123+3=")
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
set key "x"
|
||||
event generate $target <Key-$key>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package require Tk
|
||||
pack [text .t]
|
||||
focus -force .t
|
||||
foreach c [split "hello world" ""] {
|
||||
event generate .t [expr {$c eq " "?"<space>": $c}]
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Dim WshShell
|
||||
Set WshShell = WScript.CreateObject("WScript.Shell")
|
||||
WshShell.SendKeys "{Down}{F2}"
|
||||
WScript.Sleep 1000 ' one-second delay
|
||||
WshShell.SendKeys "{Left}{Left}{BkSp}{BkSp}Some text here.~" ' ~ -> Enter
|
||||
Loading…
Add table
Add a link
Reference in a new issue