Get onkeyup event

WebTextField has a KeyPressed event which maps to onkeypress. In some situations however onkeypress does not catch certain keys (in this case return/13).

I tried to catch the key press by adding the following code to the control’s shown event.

Dim js As String js = js + " var myinput= document.getElementById('"+Me.ControlID+"').getElementsByTagName('input'); " js = js + "myinput[0].setAttribute('onkeyup', ""alert(Event.which || Event.keyCode)"");" Self.ExecuteJavaScript(js)

The problem is that even though the keypress is ‘caught’, the elert shows undefined, so I can’t tell what key was pressed.

Even if I could tell what key was pressed, how could I call an xojo method.

To explain my ultimate goal/situation:

I’m using a web app as a custom user interface in SketchUp. I was using the textchange event to run a method that updates the drawing when the text field changes. The problem is that if users type to slow the update is done before they are done typing. Instead I now use the lostfocus event to only update when exiting the control. I also would like to be able to update the drawing by pressing {Enter}. The enter key fires my event in every other browser but not in the SketchUp WebDialog (I think it uses an older version of IE). I was told to use onkeyup event instead. This works with a plain HTML example but I haven’t been able to get it work in my Xojo app.

OK I’m able to catch the enter key press but how do I map that back call an Xojo method?

Use a webSDK Xojo.TriggerServerEvent.

See WebSDK in Extras within the Xojo IDE folder. The WeSDK.pdf shows how to do so.

It took me about two hours to figure it out but now I subclassed WebTextField and added a Change event that fires if a change has been made and focus is lost or enter is pressed.

Would be nice if you would share how you did it instead of just announcing it.

OK then. Custom Web Controls.xojo_binary_project

What really threw me for a loop was the fact that an ‘unused’ WebControlWrapper needed to be placed on the webpage to establish the name space. Not only that it had to be drug from the library. Adding a generic object and setting it’s supper to MyHTMLArea (WebControlWrapper subclass) didn’t work.

In the WebTextArea the change event fires even when pressing enter to make a new line. In some cases this might be undesirable.