The following functions are built into the Javascript runtime:

print(str); // print given string
version(); // return runtime version 
freemem(); // return available memory in bytes
delay(interval); // wait for the specified interval in milliseconds
random(min, max); // returns a random integer between min and max (inclusive)
getkey(); // return next keystroke from the Web UI as string, otherwise return null
getkeystore(); // get singleton instance for keystore object

The keycode returned by getkey() is the event.code value in the Javascript keyboard event, plus modifiers. So Ctrl-Q will be returned as "Ctrl+KeyQ".

Example

print(version());
print("Available memory = " + Math.round(freemem() / 1024) + "KB");
while(true) {
  var key = getkey();
  if (key != null) print("Key = " + key);
}