tighpo

1.0.1 • Public • Published

tighpo

Monitor keystrokes for a specific string and fire a callback when typed.

Note: I'm not sure this could be used maliciously, but obviously do not do that. This library is intended for fun things like easter eggs.

Install

npm i tighpo --save

Usage

import tipho from 'srraf'

tighpo('say hello', () => {
  alert('hello')
})

By default, the above will trigger the callback every time the string is matched. To trigger it only once, pass true as the third argument.

import tipho from 'srraf'

tighpo('say hello once', () => {
  alert(`hello, you won't see me again!`)
}, true)

The factory also returns a function. Call that to destroy the listener on command:

import tipho from 'srraf'

const destroy = tighpo('...', () => {
  // ...
})

destroy()

Supported keyCode Mapping

const codes = {
  65: 'a',
  66: 'b', 
  67: 'c',
  68: 'd',
  69: 'e',
  70: 'f',
  71: 'g',
  72: 'h',
  73: 'i',
  74: 'j',
  75: 'k',
  76: 'l',
  77: 'm',
  78: 'n',
  79: 'o',
  80: 'p',
  81: 'q',
  82: 'r',
  83: 's',
  84: 't',
  85: 'u',
  86: 'v',
  87: 'w',
  88: 'x',
  89: 'y',
  90: 'z',
  32: ' ',
  191: '/'
  13: '↩'
}

License

MIT License © Eric Bailey

Dependents (0)

Package Sidebar

Install

npm i tighpo

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

8.01 kB

Total Files

8

Last publish

Collaborators

  • estrattonbailey