HTMLViewer and KeyDown

How can I get Xojo’s KeyDown-event to capture arrow keys when using HTMLViewer?

Under Windows set the renderer to WebKit. Internet Explorer has a bug with arrow keys.

I should have mentioned I’m coding for OS X. But the renderer is WebKit. By default, arrow keys scroll the HTML Viewer. I need to capture the arrow keys with Xojo instead.

That’s what I was afraid you were doing. I don’t know if there is a way to prevent Xojo from passing the keys through to the HTML Viewer. What exactly are you doing with the arrow keys instead of scrolling? There might be a better way to achieve your end result.

You may want to use the window Keydown instead.

I just tested and Window.KeyDown does not fire for arrow keys… that doesn’t seem right.

The main reason for the test was to see behavior with HTML Viewer. It should be noted that a Window.KeyDown does not fire if a form element has focus in the HTML Viewer. I was unable to verify anything about arrow keys due to the above issue.

The HTMLViewer is notoriously badly behaved. It does all sorts of bad things, including not respond to keydown and not working with Drawinto.

I see that the window keydown does not work either with arrow keys.

The workaround I found was to place a texfield left of the window, outside of it’s area, with TabIndex zero, so it catches the focus. Eventually, add code to keep it that way.

The textField reports perfectly arrow keys in Keydown.

Alternatively, use ExecuteJavaScript to inject a fonction in the HTMLViewer DOM to modify the HTMLViewer title when a key is pressed while the HTMLViewer has the focus.
Then use Window.Status to return a variable to Xojo through the StatusChanged event.

You will need to go the route Michel laid out above

  • in the DocumentComplete event (Xojo) you will need to inject some JavaScript to handle the onkeydown event (JS)
  • in the onkeydown event (JS) you will need to change the window.status property (JS)
  • in the StatusChanged event (Xojo) you will need to handle the changed status to determine which arrow key has been pressed

Thanks for your answers.

I’m creating a HTML/JS-replacement for ListBox. Instead of scrolling the viewer, arrows would selected the next/previous row (and scroll depending if the row is in view). I can use JS to capture the arrow keys. At this point of development, I’m just not sure which way to go, pure JS or combination of Xojo and JS. I’d like to keep it as much “Xojo” as possible.

I do not know if you plan on selling your control, but the pure HTML/CSS/JS solution would have the advantage to be more easily adapted to Web Edition which WebListBox is rather limited. So you could sell the control for Desktop and WE. Probably even for iOS, where there is simply no ListBox at all…

If you are using the arrows keys to move around the rows in the listbox, I would recommend to just leave it to the JavaScript code to handle it and just pass back a RowChanged event (or something similar)…

Thanks! I will do that.

Another thing, is there a way to disable the smooth scrolling of HTMLViewer?

[quote=176768:@Thomas White]Thanks! I will do that.

Another thing, is there a way to disable the smooth scrolling of HTMLViewer?[/quote]

You can disable scrolling entirely in JavaScript, then you can manage it manually.

There was a similar topic here

I’m using JS (scrollTo) to scroll. When testing in Chrome the scrolling is instant but in HTMLViewer it’s smooth.

Probably a Mac OS X animation stuff you got to disable with some declare. I would not know where to look, but am sure there are some gurus here who do.

The only way I know how to do it, would be to try disabling Core Animation. This would have to be done using Xojo code (as I don’t think JavaScript can call OS APIs).

The latest edition of the XDev magazine includes a Core Animation crash course which will help get you started with Core Animation.