Calling kotlin js from HTML not working

I’m building a small website using kotlin and kvision. I need to detect keyboard events, specifically for the arrow keys. I’ve been wrestling with this for a while and nothing I try will produce keypress or keydown events within kotlin for arrow key presses, although I do get keypress events for normal character keys.

Anyway, my workaround will be to hopefully just detect the arrow key events in HTML:

<body onkeydown="NAP_web.nap.foo()">

my root kotlin package is nap, and foo is defined globally in nap.

Based on the docs I should use my module name before my root package. I can’t figure out for sure what my module name is, but I’m pretty sure this is right. NAP_web is the name of my project folder and the generated js that I upload to the webpage is called NAP_web.bundle.js.

But I get the error:

Uncaught ReferenceError: NAP_web is not defined
    at HTMLBodyElement.onkeydown

Perhaps there’s a fix to get key events from arrow keys without needing html but being able to call kotlin-generated-js from html seems like a more general problem I should focus on fixing first. Do I have the wrong module name or is there something else I should try?

I ended up solving the problem related to key events without having to call javascript from html. However I’d still be curious if anyone knows if js from html is possible from kotlin generated js.

I use Kotlin JS and I have keydown arrow key handlers, but I’m not using kvision. My Kotlin code has access to the DOM elements and can call

element.addEventListener("keydown", handler) // or ...
window.addEventListener("keydown", handler)

Have you tried that and your handlers don’t get called?

Rob