evanw / skew

A web-first, cross-platform programming language with an optimizing compiler
https://evanw.github.io/skew-lang.org/
MIT License
413 stars 16 forks source link

How to catch mouse and keyboard events? #5

Closed PifyZ closed 9 years ago

PifyZ commented 9 years ago

I did not find anywhere how to capture keyboard and mouse events. How can this be done?

evanw commented 9 years ago

Skew is just a programming language and as such doesn't have an intrinsic way to interact with the mouse and keyboard. What you're looking for is a library. I'm working on a package manager that will make it easy to use and contribute libraries, but for now you can use any library you'd like. For example, to use jQuery:

@import {
  const document dynamic
  @rename("$")
  const jQuery dynamic
}

@entry
def main {
  jQuery(document).on("mousedown", e => {})
  jQuery(document).on("keydown", e => {})
}

You can also use plain old DOM calls. If you also pass the files in https://github.com/evanw/skew-imports/tree/master/html5 to the compiler then DOM calls will even be type-checked. That would look like this:

@entry
def main {
  document.addEventListener("mousedown", (e HTMLMouseEvent) => {})
  document.addEventListener("keyboard", (e HTMLKeyboardEvent) => {})
}

I've got a library I've been working on that adds a nice interface in front of all of this, but it's not ready to be released yet.

PifyZ commented 9 years ago

Thank you so much for the answer!

I love your language, good continuation.

evanw commented 9 years ago

This should now be fixed. There is a new "Getting Started" section on http://skew-lang.org/ that has examples with input and output for both browser and command-line apps.