keywatcher

1.2.0 • Public • Published

keywatcher

JS For watching key inputs

Two functions:

watchKeys(inputEl, keyPress, onDelete)

Params

  • inputEl: the element to listen on
  • keyPress: a callback for any keypressed
  • onDelete: a callback for the backspace or delete key pressed

watchKeyup(inputEl, keyUp)

Params

  • inputEl: the element to listen on
  • keyUp: the callback for a key released

Example

var el = document.getElementById('element')
 
watchKeys(el, function onKeyPress (e) {
  console.log('Key pressed: '+e.key)
}, function onDelete (e) {
  console.log('Either backspace or delete: '+e.key)
})
 
watchKeyup(el, function onKeyUp (e) {
  console.log('Key released: '+e.key)
})

Notes

  • watchKeys uses the keyPressed event, which is currently deprecated. See MDN
  • the keyPress callback is not called when the delete or backspace key is pressed

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.01latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.01
1.1.30
1.1.20
1.1.10
1.1.01
1.0.10
1.0.01

Package Sidebar

Install

npm i keywatcher

Weekly Downloads

3

Version

1.2.0

License

ISC

Last publish

Collaborators

  • jman294