28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * D Port:
|
|
11 * Thomas Demmer <t_demmer AT web DOT de>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.snippets.Snippet146;
|
|
14
|
|
15 /*
|
|
16 * UI Automation (for testing tools) snippet: post key events
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 *
|
|
21 * @since 3.0
|
|
22 */
|
|
23 import org.eclipse.swt.SWT;
|
|
24 import org.eclipse.swt.widgets.Display;
|
|
25 import org.eclipse.swt.widgets.Event;
|
|
26 import org.eclipse.swt.widgets.Shell;
|
|
27 import org.eclipse.swt.widgets.Text;
|
|
28
|
|
29 import java.lang.all;
|
|
30
|
|
31 import tango.core.Thread;
|
|
32 import tango.text.Unicode;
|
|
33
|
|
34 void main(String[] args) {
|
|
35 Display display = new Display();
|
|
36 Shell shell = new Shell(display);
|
|
37 Text text = new Text(shell, SWT.BORDER);
|
|
38 text.setSize(text.computeSize(150, SWT.DEFAULT));
|
|
39 shell.pack();
|
|
40 shell.open();
|
|
41 Thread thread = new Thread({
|
|
42 String string = "Love the method.";
|
|
43 String lstring;
|
|
44 lstring. length = string.length;
|
|
45 toLower(string, lstring);
|
|
46 for (int i = 0; i < string.length; i++) {
|
|
47 char ch = string.charAt(i);
|
|
48 bool shift = isUpper(ch);
|
|
49 ch = lstring.charAt(i);
|
|
50 if (shift) {
|
|
51 Event event = new Event();
|
|
52 event.type = SWT.KeyDown;
|
|
53 event.keyCode = SWT.SHIFT;
|
|
54 display.post(event);
|
|
55 }
|
|
56 Event event = new Event();
|
|
57 event.type = SWT.KeyDown;
|
|
58 event.character = ch;
|
|
59 display.post(event);
|
|
60 try {
|
|
61 Thread.sleep(10/1000.);
|
|
62 } catch (InterruptedException e) {}
|
|
63 event.type = SWT.KeyUp;
|
|
64 display.post(event);
|
|
65 try {
|
|
66 Thread.sleep(100/1000.0);
|
|
67 } catch (InterruptedException e) {}
|
|
68 if (shift) {
|
|
69 event = new Event();
|
|
70 event.type = SWT.KeyUp;
|
|
71 event.keyCode = SWT.SHIFT;
|
|
72 display.post(event);
|
|
73 }
|
|
74 }
|
|
75 });
|
|
76 thread.start();
|
|
77 while (!shell.isDisposed()) {
|
|
78 if (!display.readAndDispatch()) display.sleep();
|
|
79 }
|
|
80 display.dispose();
|
|
81 }
|
|
82
|