File: Example.js

Recommend this page to a friend!
  Classes of Martin Barker   CanvasGame.Controls   Example.js   Download  
File: Example.js
Role: Example script
Content type: text/plain
Description: this shows how you can use the object to easily bind events to key strokes
Class: CanvasGame.Controls
Bind pressed keys to callback handler functions
Author: By
Last change:
Date: 12 years ago
Size: 3,730 bytes
 

Contents

Class file image Download
//Example Script's CanvasGame.Controls.init(); // bind the function to when the k key is released CanvasGame.Controls.bindKeyUp(CanvasGame.Controls.getKeyCode('k'), function(){ alert("you released the 'k'"); }); // bind the function to when the k key is pressed down CanvasGame.Controls.bindKeyDown(CanvasGame.Controls.getKeyCode('k'), function(){ alert("you pressed the 'k' key down"); }); // bind more than one key at once KeyUpEvents = { // a standard key 'k':function(){ alert('key pressed down'); }, // command keys 'backspace':function(){ alert('pressed down'); }, 'tab':function(){ alert('key pressed down'); }, 'enter':function(){ alert('key pressed down'); }, 'shift':function(){ alert('key pressed down'); }, 'ctrl':function(){ alert('key pressed down'); }, 'alt':function(){ alert('key pressed down'); }, 'break':function(){ alert('key pressed down'); }, 'caps_lock':function(){ alert('key pressed down'); }, 'escape':function(){ alert('key pressed down'); }, 'page_up':function(){ alert('key pressed down'); }, 'page_down':function(){ alert('key pressed down'); }, 'end':function(){ alert('key pressed down'); }, 'home':function(){ alert('key pressed down'); }, 'left_arrow':function(){ alert('key pressed down'); }, 'up_arrow':function(){ alert('key pressed down'); }, 'right_arrow':function(){ alert('key pressed down'); }, 'down_arrow':function(){ alert('key pressed down'); }, 'insert':function(){ alert('key pressed down'); }, 'delete':function(){ alert('key pressed down'); }, 'left_windows_key':function(){ alert('key pressed down'); }, // numpad keys 'num_lock':function(){ alert('key pressed down'); }, 'numpad_0':function(){ alert('key pressed down'); }, 'numpad_1':function(){ alert('key pressed down'); }, 'numpad_2':function(){ alert('key pressed down'); }, 'numpad_3':function(){ alert('key pressed down'); }, 'numpad_4':function(){ alert('key pressed down'); }, 'numpad_5':function(){ alert('key pressed down'); }, 'numpad_6':function(){ alert('key pressed down'); }, 'numpad_7':function(){ alert('key pressed down'); }, 'numpad_8':function(){ alert('key pressed down'); }, 'numpad_9':function(){ alert('key pressed down'); }, 'numpad_*':function(){ alert('key pressed down'); }, 'numpad_+':function(){ alert('key pressed down'); }, 'numpad_-':function(){ alert('key pressed down'); }, 'numpad_/':function(){ alert('key pressed down'); }, // function keys 'f1':function(){ alert('key pressed down'); }, 'f2':function(){ alert('key pressed down'); }, 'f3':function(){ alert('key pressed down'); }, 'f4':function(){ alert('key pressed down'); }, 'f5':function(){ alert('key pressed down'); }, 'f6':function(){ alert('key pressed down'); }, 'f7':function(){ alert('key pressed down'); }, 'f8':function(){ alert('key pressed down'); }, 'f9':function(){ alert('key pressed down'); }, 'f10':function(){ alert('key pressed down'); }, 'f11':function(){ alert('key pressed down'); }, 'f12':function(){ alert('key pressed down'); }, //Special Charters ';':function(){ alert('key pressed down'); }, '=':function(){ alert('key pressed down'); }, ',':function(){ alert('key pressed down'); }, '-':function(){ alert('key pressed down'); }, '.':function(){ alert('key pressed down'); }, '/':function(){ alert('key pressed down'); }, '`':function(){ alert('key pressed down'); }, '(':function(){ alert('key pressed down'); }, ')':function(){ alert('key pressed down'); }, '\\':function(){ alert('key pressed down'); }, ')':function(){ alert('key pressed down'); }, '\'':function(){ alert('key pressed down'); }, }; CanvasGame.Controls.bindKeyUp(KeyUpEvents);