How to use the is-hotkey.toKeyName function in is-hotkey

To help you get started, we’ve selected a few is-hotkey examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / BlockEditor / plugins / SetMarksOnKeyComboPlugin.ts View on Github external
import isKeyHotkey, {toKeyName} from 'is-hotkey'
import {SlateEditor} from '../typeDefs'

type Options = {
  decorators?: string[]
}

// This plugin makes keyboard shortcuts for decorators

const isStrongHotkey = isKeyHotkey('mod+b')
const isEmphasisHotkey = isKeyHotkey('mod+i')
const isUnderlinedHotkey = isKeyHotkey('mod+u')
const isCodeHotKey = isKeyHotkey("mod+'")

const modKeyPlatformName = toKeyName('mod')

export const keyMaps = {
  strong: `${modKeyPlatformName} + b`,
  em: `${modKeyPlatformName} + i`,
  underline: `${modKeyPlatformName} + u`,
  code: `${modKeyPlatformName} + '`
}

export default function SetMarksOnKeyComboPlugin(options: Options = {}) {
  const decorators = options.decorators || []
  return {
    onKeyDown(event: React.KeyboardEvent, editor: SlateEditor, next: (arg0: void) => void) {
      let mark
      if (isStrongHotkey(event)) {
        mark = 'strong'
      } else if (isEmphasisHotkey(event)) {
github giladv / orkan / src / utils / keyboard-utils.js View on Github external
const handleBase = e => {
			const sanitizedKey = toKeyName(e.key);
			if((key === null || key === sanitizedKey) && !e.repeat){
				handle(e);
			}
		};
github giladv / orkan / src / utils / keyboard-utils.js View on Github external
handleNativeEvent(e){
		const sanitizedKey = toKeyName(e.key);

		if(e.repeat){
			return;
		}

		this.downKeys = this.downKeys.filter(key => key !== sanitizedKey);

		if(e.type === 'keydown'){
			this.downKeys.push(sanitizedKey);
		}
	}

is-hotkey

Check whether a browser event matches a hotkey.

MIT
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis