Skip to main content

KeyboardEvents are consumed by the WebBrowser

16 replies [Last post]
lrcusts
Offline
Joined: 2005-12-02

If the webbrowser is active in an window of my application then no acclerator or shortcut of the menu (of the frame that contains the child-window with the webbrowser) can be used. reason is that the webbrowser consumes all keyboard events.
is there an possibility to get the keyboard events?

i hope anybody can help me.
regards,

thomas

Message was edited by: lrcusts

Message was edited by: lrcusts

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
lrcusts
Offline
Joined: 2005-12-02

does that mean that NO "shift+anykey","ctrl+anykey","alt+anykey" but all other keyboard-events can be received in the program surrounding the browser component?

if this is true, then the initial problem is'nt solved.
exactly all keyboard-events which the browser does not interpret as actions should be forwarded to the outer application.

PLEASE consider a correction.

rajashree
Offline
Joined: 2008-02-11

Hi,

I am using the jdic-20061102-bin-crossplatform for the WebBrowser on Mac OS, I am unable to type into the textfield of the webpages in the browser. Please let me know if this is still an issue on Mac or has this been fixed.

Thanks,
Rajashree

madroadie
Offline
Joined: 2006-04-20

its a bit more tricky then that, you need to add custom events to the Java and C++ and rebuild the entire thing. Proceed knowing you have to merge updates. Here is and example of what I did, and it works great. PS, I have only tried this with the IE version.

You need to add some events,
I added two to the Java. In WebBrowserEvent

public static final int WEBBROWSER_KEYDOWN = 34 + WEBBROWSER_FIRST;

public static final int WEBBROWSER_KEYUP = 35 + WEBBROWSER_FIRST;

In the C++ (Message.h) I added CEVENT_KEY_UP and CEVENT_KEY_DOWN in
#define CEVENT_KEY_DOWN 3034
#define CEVENT_KEY_UP 3035

// Hide the Instance ID.
//
void BrowserWindow::SendSocketMessage(int event, const char * pData)
{
if (pData)
::SendSocketMessage(m_InstanceID, event, pData);
else
::SendSocketMessage(m_InstanceID, event);
}

#define URL_BUFSIZE 2048

BOOL BrowserWindow::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam != VK_CONTROL
&& pMsg->wParam != VK_MENU && pMsg->wParam != VK_SHIFT)
{
char buffer[URL_BUFSIZE] = {'\0'};

bool cntrDown = ::GetAsyncKeyState(VK_CONTROL) & 0x8000 ? true : false;

bool altDown = ::GetAsyncKeyState(VK_MENU) & 0x8000 ? true : false;

bool shiftDown = ::GetAsyncKeyState(VK_SHIFT) & 0x8000 ? true : false;

sprintf(buffer, "CtrlKeyDown=%ld AltKeyDown=%ld ShiftDown=%ld KeyCode=%ld", cntrDown, altDown, shiftDown, pMsg->wParam);

//::MessageBox(NULL, buffer, "WM_KEYDOWN", MB_OK);
SendSocketMessage(CEVENT_KEY_DOWN, buffer);
}
else if (pMsg->message == WM_KEYUP && pMsg->wParam != VK_CONTROL
&& pMsg->wParam != VK_MENU && pMsg->wParam != VK_SHIFT)
{
char buffer[URL_BUFSIZE] = {'\0'};
bool cntrDown = ::GetAsyncKeyState(VK_CONTROL) & 0x8000 ? true : false;

bool altDown = ::GetAsyncKeyState(VK_MENU) & 0x8000 ? true : false;

bool shiftDown = ::GetAsyncKeyState(VK_SHIFT) & 0x8000 ? true : false;

sprintf(buffer, "CtrlKeyDown=%ld AltKeyDown=%ld ShiftDown=%ld KeyCode=%ld", cntrDown, altDown, shiftDown, pMsg->wParam);
//::MessageBox(NULL, buffer, "WM_KEYUP", MB_OK);
SendSocketMessage(CEVENT_KEY_UP, buffer);

I listen for the custom event in WebBrowser.java and parse out the event parameters like this

else if (WebBrowserEvent.WEBBROWSER_KEYDOWN == eid || WebBrowserEvent.WEBBROWSER_KEYUP == eid)
{
String data = e.getData();
//CtrlKeyDown=%ld AltKeyDown=%ld ShiftDown=%ld KeyCode=%ld
if (data != null)
{
boolean isCtrlDown = false;
boolean isAltDown = false;
boolean isShiftDown = false;
int keyCode = 0;

StringTokenizer tokenizer = new StringTokenizer(data,
" ");

while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
if (token != null)
{
if (token.startsWith("CtrlKeyDown="))
{
isCtrlDown = Integer.parseInt(token.replaceFirst("CtrlKeyDown=", "")) == 1;
}
else if (token.startsWith("AltKeyDown="))
{
isAltDown = Integer.parseInt(token.replaceFirst("AltKeyDown=", ""))== 1;
}
else if (token.startsWith("ShiftDown="))
{
isShiftDown = Integer.parseInt(token.replaceFirst("ShiftDown=", ""))== 1;
}
else if (token.startsWith("KeyCode="))
{
keyCode = Integer.parseInt(token.replaceFirst("KeyCode=", ""));
}
}
else
break;
}
boolean isDownEvent = eid == WebBrowserEvent.WEBBROWSER_KEYDOWN;
onKeyEvent(isDownEvent, isCtrlDown, isAltDown, isShiftDown, keyCode);
}
}

public void onKeyEvent(boolean isDownEvent, boolean isCtrlDown, boolean isAltDown, boolean isShiftDown, int keyCode)
{
// TODO: Forward to custom listeners, etc...
}

ashikaumanga
Offline
Joined: 2008-04-01

Hi Madroadie,

I have the same problem ,ie when I press Ctrl+N in IE a new Explorer pops out.
For tried to compile only the ieEmbed.cpp ,but i need to have Windows Platform SDK February 2003 , cuz later versions does not support for VC 6++.I couldnt find this SDK.And tried with a later 2003 SDK and with it project ddnt get compiled.

Do u have the fixed IeEmbed.exe ?
How to find the Windows Platform SDK February 2003 ?

thanks and best regards
umanga

madroadie
Offline
Joined: 2006-04-20

Which Browser are you using, IE or Mozillia? I haven't done much work with Mozillia, so that could be different. If your using IE, you can trap the Key Board events in the Application PreTranslateMessage, and then don't dispatch them to control site. I was just reviewing the COM events supported by IE, and they do not fire keyboard processing events, most likely for security reasons. You will have to rebuild the source but its worth it..

Here is an example for any key down while the control key is pressed.

IeEmbed.cpp

if (msg.message == WM_KEYDOWN &&
!(::GetAsyncKeyState(VK_CONTROL) & 0x8000))
{
printf("Control key is down);
}

You should hook it up around here in IeEmbed.cpp...

int size = ABrowserWnd.GetSize();
for (int i = 0; i < size; i++) {
BrowserWindow *pBrowserWnd = (BrowserWindow *)ABrowserWnd[i];
if (pBrowserWnd && pBrowserWnd->PreTranslateMessage(&msg)) {
break;
}
}

lrcusts
Offline
Joined: 2005-12-02

thank you for your reply.

i see some drawbacks in your solution.
first it makes me necessary to build the ieembed binary. so i have always to rebuild if an newer version is available, to stay up-to-date.

the second point is that i dont know the messages the browser would interprate (e.g. Alt + CursorLeft has the meaning to go one site back in der browser-history). i want to let the browser use all of the keyboard-events he uses to react, but i want the remaining events to go to the outer window in my application.

Message was edited by: lrcusts

lrcusts
Offline
Joined: 2005-12-02

Why there is no answer to my statment?
Can anyone give me a suitable solution for the problem above.

michael_shan
Offline
Joined: 2005-05-29

Hi,

We'll take a look into this issue.

lrcusts
Offline
Joined: 2005-12-02

Have you taken a look on this issue?

Is there a (soon) solution possible?

I really hope that it will be possible, because i use the webbrowser in an big application where the browser is an small part from. So it should not consume all the keyboard-actions if it is visible.

michael_shan
Offline
Joined: 2005-05-29

Hi,

Bug https://jdic.dev.java.net/issues/show_bug.cgi?id=415 has been filed for it. We've worked out a solution for IE and still need some works for mozilla.

I think this fix can be available in our next release(Still can't tell the exact date).

If you are hurry to get it, we can provide you changed cpp and java files in the bug's attachment,perhaps you have to build them by yourself.

thanks,
Michael

lrcusts
Offline
Joined: 2005-12-02

thank you for your answer.

i am thankful that you filled an issue to correct this problem.

therefore i wait patiently for the next release.

matr
Offline
Joined: 2006-08-18

Hi,
According the issue 415 https://jdic.dev.java.net/issues/show_bug.cgi?id=415 this problem has been fixed, but i cannot seem to be able to catch when a key is pressed. Has any1 managed to get this working. i am using the release 20061102.
Thanks

dongdongyang
Offline
Joined: 2006-01-08

Hi,matr,
Sorry if I confused you. The controled key events only include menu key events in embeded browser project, such as "shift+anykey","ctrl+anykey","alt+anykey".

matr
Offline
Joined: 2006-08-18

My bad, Thanks for clearing that up.

Anand Kulkarni

Hi,

We are using JDIC in a swing application. It renders
the HTML page. Now we want to print that web page. We
call webBrowser.print() method for the same.

Now, in our application, we want to print 2 HTML files
in series. So, we write:

webBrowser.setURL(new URL("file:///c:/pageOne.html"));
System.out.println("isInitialized() :
"+webBrowser.isInitialized());
webBrowser.print();

webBrowser.setURL(new URL("file:///c:/pageTwo.html"));
System.out.println("isInitialized() :
"+webBrowser.isInitialized());
webBrowser.print();

It is noticed that unless the browser is initialized,
we can not print the HTML file. When I run the above
code, JDIC prints pageOne.html properly but it fails
to print pageTwo.html since pageTwo.html is not
initialized yet.

So, the question is:
Is there any function in the WebBrowser that blocks
the code until the web page is fully initialized?

Waiting for the reply.

regards,

Anand

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: jdic-unsubscribe@jdic.dev.java.net
For additional commands, e-mail: jdic-help@jdic.dev.java.net

Anand Kulkarni

Hi,

I have a HTML file having two pages for printing. The
contents of the file are:


CLM Test Page 1

CLM Test Page 2


In the above code,

is used for page
breaks. If I open this file in the IE and give print
command then it prints 2 pages.

Now I write JDIC program and load the same HTML file
in WebBrowser. When I say:

public void downloadCompleted(WebBrowserEvent event) {
webBrowser.print();
}

It opens Print window twice because I have 2 HTML
pages.
And if I say:

public void documentCompleted(WebBrowserEvent event) {
webBrowser.print();
}

Then it prints only last HTML page.

This is really surprising.

Suppose I load a HTML document having 100 pages then
how can I print all 100 pages with a single
PrintDialog box?

Waiting for the reply.
regards,

Anand

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: jdic-unsubscribe@jdic.dev.java.net
For additional commands, e-mail: jdic-help@jdic.dev.java.net