Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { createContext } from './hotkeys';
const c = createContext();
// Alerts when "no way" is typed in.
c.register('n o space w a y', () => {
alert('Yes way!');
});
/*
It replaces the native search behaviour when pressing ctrl+f
Note, the callback gets the event from the last key,
that is matched in the given sequence
*/
c.register('ctrl+f', (event) => {
// prevent the native search behavior
event.preventDefault();
const value = prompt('What you are looking for?');
window.location.href = `https://www.google.com/?q=${value}`;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment