close web dialog with escape key

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
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

This may be related: <> WebTextField.KeyPress event Does Not Detect the Esc Key