Skip to content

Instantly share code, notes, and snippets.

@nidate
Created December 9, 2015 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nidate/783087407b8eca62c3be to your computer and use it in GitHub Desktop.
Save nidate/783087407b8eca62c3be to your computer and use it in GitHub Desktop.
HTMLドキュメント内のキーイベントをすべて受け取る
<html>
<script type="application/javascript">
document.addEventListener('DOMContentLoaded', function(){
var elem = document.querySelector('.input');
document.addEventListener('keydown', function(e) {
elem.textContent += JSON.stringify(e);
e.preventDefault();
});
});
</script>
<style>
.input {
width: 300px;
height: 300px;
background-color: lightgray;
}
</style>
<div class="input">
</div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment