close web dialog with escape key

Hello
as might close a web dialog by pressing the escape key,
I have done the following but does not work

if Details.KeyCode = Details.KeyEscape then
Me.Close
end if

I put the code in the keyPressed event in the dialog but it just does not work, but the pointer is hidden until you move
would greatly appreciate your help
thanks

This may be related: <https://xojo.com/issue/20562> WebTextField.KeyPress event Does Not Detect the Esc Key