https://github.com/32teeth/multikey.js
multi key press event listener
https://github.com/32teeth/multikey.js
Last synced: 12 months ago
JSON representation
multi key press event listener
- Host: GitHub
- URL: https://github.com/32teeth/multikey.js
- Owner: 32teeth
- Created: 2015-05-06T00:28:42.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-04T14:20:09.000Z (about 11 years ago)
- Last Synced: 2025-04-08T20:48:43.611Z (about 1 year ago)
- Language: CSS
- Size: 238 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# multikey.js
-----------
##introduction
**multikey.js** is a small script that enables keypress event binding and integrates nicely to other libraries and can be used to extend your interactive canvas or html5 games.
### design pattern
**multikey.js** is built on a revealing module pattern exposing four (4) core methods.
* setup()
* bind()
* unbind()
* handler()
### usage
**multikey.js** is an IIFE *(immediately-invoked function expression)* simply include the file at the bottom of your html page before the closing ***body*** tag
/*
** @description include mutlikey.js or mutlikey.min.js
*/
<script src="mutlikey.min.js"></script>
</body>
####*setup()*
Once you have included the multikey.js file, you can invoke the process by calling the setup method. Setup can take from 1 to 3 parameters. *cbfunc* is required
#####With a callback function
```
/*
@param cbfunc {function} callback function to recieve the map object from multikey.js
*/
setup(cbfunc)
```
What is returned to the ***cbfunc*** is an object with the character key as the property and the value will be either **true** *(pressed)* or **false** *(released)*
example:
```
{
q:false,
w:true,
e:true,
r:false
}
```
do whatever you wish with the returned object within your callback function
#####With key set restrictions
```
/*
@param cbfunc {function} callback function to recieve the map object from multikey.js
@param keys {string} this is a string of keyboard keys to create a limited set, unset, all keys are recorded
@description keys parameter examples "abc", "qwer", "wasd"
*/
setup(cbfunc, keys)
```
#####With arrow keys
```
/*
@param cbfunc {function} callback function to recieve the map object from multikey.js
@param keys {string} this is a string of keyboard keys to create a limited set, unset, all keys are recorded
@description keys parameter examples "abc", "qwer", "wasd"
@param arrows {boolean} if set to true, multikey.js also watches the arrow keys on a keyboard
*/
setup(cbfunc, keys, arrows)
```
##example
----------

view the [example](index.html) file for more information.
or check out the [live example](http://multikey.32teeth.org/) here