"Enter" key is not working in SU WebDialogs. Bug?
-
Hello,
I've encountered a problem while making a GUI for a SketchUp plugin. I need to get an input confirmation from the user by pressing "Enter key", but I have found out that no KeyDown event is firing in SketchUp WebDialogs, but it is firing in a regular browser (IE/Chrome/Firefox)
the simple code if here:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml;lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <!--<meta http-equiv="X-UA-Compatible" content="EmulateIE8"> --> <title>Test Window</title> <script type="text/javascript"> document.onkeypress = function (e) { e = e || window.event; var charCode = e.charCode || e.keyCode; if(charCode == 13) { alert("key pressed"); } }; </script> </head> <body> </body> </html>Is it a common thing or I'm the only one who is getting the restriction?
I've checked this behaviour in SketchUp 8 and 2013 on Win7 and Win8 and have got consistent results.
How WebDialog web browser is different from regular IE on the system? -
No 'key-presses' get processed BUT using
document.onkeydowninstead will work - so change it.
To see what's happening temporarily replace
if(charCode == 13) { alert("key pressed"); }
with just
alert(charCode);
You'll see the number of each key-down you do - '13' is Enter... -
I always recommend that people use a JS framework to take care of the compatibility issues - leaving you to interact with a unified API. My personal preference is jQuery.
I used that in SKUI where I capture ESC and Enter: https://github.com/thomthom/SKUI/blob/master/src/SKUI/js/ui.window.js#L21
-
Ah, so simple

Thank you guys!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement