"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.onkeydown
instead 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!
Advertisement