opal / opal-browser

Browser support for Opal.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyboard/Mouse api?

drewhamlett opened this issue · comments

I'm trying to wrap my head around it the event api, more specifically keyboard/mouse. Is there an example you can give me real quick. Doesn't have to be detailed. Thanks.

Oh gotcha. So it's attached to the $window object by default. So keybaord stuff is like

$window.on('keydown') do |e|
  $console.log(e.code)
end

I don't know what I was trying to do before. Haha

commented

In that source I'm using a framework that deals with deferring the events to a rendered element.

But even handling semantics work like in JavaScript, if you want to catch all keydowns on the whole page, you should indeed observe the event on the window/document.

commented

Also useful this and this.

Yea that's where I was hung up at. I've been looking over the source for a while. I thought I had to instantiate some kind of Keyboard object. Didn't know it was attached to the $window/$document variable.

commented

Yeah, there's no Keyboard or Mouse abstraction, but I don't see why there shouldn't be in the future. For now you'll just have to deal with the standard event handling the browser provides.