I have a Java SWT application (version 1.6) where I'm using swt.Browser to display an embedded browser. However, swt.Browser is based on IE, and I can't update SWT to use Browser with EDGE.
To work around this issue, we've created a parallel Selenium WebDriver application that launches an EDGE-type browser. In the SWT app, I retrieve the PID of EDGE, and using org.eclipse.swt.internal.win32.OS library, I manage to set the EDGE window as a child of the SWT shell.
In the EDGE window, I can click with the mouse, but it doesn't capture key events. Key events are captured in the SWT shell. Any ideas on why key events aren't being picked up in the EDGE window?
In the open() method of Shell we use the following java code to position the EDGE window
import org.eclipse.swt.internal.win32.OS;
//...
OS.ShowWindow(iWndMyWebDriver, OS.SW_HIDE);
OS.SetWindowLong(iWndMyWebDriver, OS.GWL_STYLE, OS.WS_CHILD & ~OS.WS_POPUP);
OS.SetParent(iWndMyWebDriver, handle);
int style = OS.GetWindowLongA(iWndMyWebDriver, OS.GWL_STYLE);
style = style & ~OS.WS_SYSMENU;
style = style & ~OS.WS_MAXIMIZEBOX;
style = style & ~OS.WS_MINIMIZEBOX;
style = style & ~OS.WS_CAPTION;
OS.SetWindowLongA(iWndMyWebDriver, OS.GWL_STYLE, style);
if (!isDisposed()) {
OS.SetWindowPos(iWndMyWebDriver, 0, -1, -2, getBounds().width, 495, 4 + 32);
}
OS.BringWindowToTop(iWndMyWebDriver);
RECT r = new RECT();
r.left = 0;
r.top = 0;
OS.RedrawWindow(iWndMyWebDriver, r, 0, 256 + 512 + 1 + 2 + 128);
OS.ShowWindow(iWndMyWebDriver, OS.SW_SHOW);
OS.SetForegroundWindow(iWndMyWebDriver);
if (!isVisible()) {
setVisible(true);
Pointer pHwnd = new Pointer(this.handle);
User32.INSTANCE.ShowWindow(pHwnd, 9);
User32.INSTANCE.SetForegroundWindow(pHwnd);
UtilsOS.SetWindowAlwaysOnTop(this.handle, true);
User32.INSTANCE.SetActiveWindow(pHwnd);
setFocus();
UtilsOS.SetWindowAlwaysOnTop(this.handle, false);
}
Edit: I have added the following code:
addKeyListener( new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println( "key Released");
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println( "Key pressed");
}
});
and when I have the focus on the EDGE and press a key, the two events are captured, I want those events to go to the browser.