Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created August 2, 2013 07:04
Show Gist options
  • Select an option

  • Save draftcode/6138007 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/6138007 to your computer and use it in GitHub Desktop.
noHandle = false
focusHandler = (e)->
if e.target.isContentEditable
noHandle = true
else
nohandle = false
keypressHandler = (e)->
return if noHandle
switch String.fromCharCode(e.keyCode)
when 'h'
window.history.back()
when 'l'
window.history.forward()
when 'j'
window.scrollBy(0, 100)
when 'k'
window.scrollBy(0, -100)
else
console.log(e.keyCode)
console.log(String.fromCharCode(e.keyCode))
document.addEventListener("keypress", keypressHandler, true)
document.addEventListener("focus", focusHandler, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment