1 /*
2 Jiffie Plugin for Jameleon - An Internet Explorer plug-in for Jameleon
3 Copyright (C) 2004 Christian W. Hargraves (engrean@hotmail.com) and
4 Matthias Marschall (matthias@marschalls.de)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 package net.sf.jameleon.plugin.jiffie.util;
21
22 import com.jacob.com.Dispatch;
23 import com.jacob.com.Variant;
24
25 public class IEUtility {
26
27
28 public static boolean sendKeys(String title, String keys, int maxWaitTimeInHundrendths) {
29 Variant[] argv = new Variant[1];
30 Dispatch wsh = new Dispatch("WScript.Shell");
31 argv[0] = new Variant(title);
32 int count = 0;
33 boolean windowFound = false;
34 while (!windowFound && count < maxWaitTimeInHundrendths) {
35 if (Dispatch.callN(wsh, "AppActivate", argv).toBoolean() == true) {
36 windowFound = true;
37 break;
38 }
39
40 try {
41 Thread.sleep(100);
42 } catch (InterruptedException ex) {
43 // ignore interrupted sleep
44 }
45 ++count;
46 }
47 if (windowFound) {
48 argv[0] = new Variant(keys);
49 Dispatch.callN(wsh, "SendKeys", argv);
50 wsh.safeRelease();
51 }
52 return windowFound;
53 }
54
55 }