How to create a shortcut for a button

Is there a way to make a button on WebDialog respond to the Enter and/or Return key? In other words If I hit the Enter key it is just as if I hit an OK button.

Seems like this should be easy but I cannot find a clear discussion on the forum or in the docs. Need this to work in both mac and windows browsers.

Thanks,

John

Check out the KeyPressed event

I tried the KeyPressed event but where does the KeyPressed event go. I tried it in the button and I tried on the WebDialog. The event will not fire. Is there something else I need to do?

This should work. You might need to but it in a WebTextField? At least thats where I tried and got it working.

If Details.KeyCode = 13 or Details.KeyCode = 3 then
  …
End If

@Albin K Thanks, but the problem isn’t the code but when the event fires . From the docs on the KeyPressed event…

So I put the event in every text field on the dialog and it works ok, but only if the cursor is in one of those fields.

I want it to fire regardless of where the cursor is, The only way I can see to do that is to add the KeyPessed event to the WebPage, but then it would be active all the time and the dialog properties would not be in scope.

What about a “confirm” dialog where there is no WebTextField.

Use the WebPage Keypressed event.

I have been trying to get it to work in the WebPage Keypressed event. I ony want it to be active while the WebDialog is being shown so I have been trying to add it to the WebDialog Shown, but the KeyPressed event is not available as a property. I thought this would work (SiteDocumentLibrary is the WebPage name)…

AddHandler SiteDocumentLibrary.KeyPressed, AddressOf Validate_Close

If I just go ahead and type .KeyPressed and try to run it I get…

[quote]mw_RequestUserPW.Shown, line 11
Type mismatch error. Expected delegate Delegate( SiteDocumentLibrary.SiteDocumentLibrary, REALbasic.KeyEvent ), but got delegate Delegate( )
AddHandler SiteDocumentLibrary., AddressOf Validate_Close [/quote]

How do you add the handler to the WebPage in code?

I fail to understand. Why would you want to add a handler in code when you can easily do that in the IDE ?

For webdialog, you can use a property on the webpage that will serve to display it, and just check in KeyPressed handler that is not nil.

Keep using the Keypressed event of the WebPage.

@Michel Bujardet For webdialog, you can use a property on the webpage that will serve to display it, and just check in KeyPressed handler that is not nil.

Maybe I don’t understand. Could you explain your suggestion a bit further? How does the property display the WebDialog?

I am displaying vairous WebDialogs at various times in the web app. As an example in the web page open event I am displaying a WebDialog login window.

Instead of doing something like

Dim WD as Palette1 WD.Show

You add WD to the WebPage as property :

WD as Palette1

Then you do :

WD = New Palette1 WD.Show

In the WebPage Keypressed event, you do :

If WD <> Nil then // Do stuff end if

@Michel Bujardet I got it! Thanks!!

Once again, thanks to you guys on the forum, I have learned something new.