- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
addEventListener for keydown on HTML5 Canvas
Use the tabindex attribute on the canvas element for addEventListener on Canvas −
var myTarget, myCanvas; window.onload = function() { myCanvas = document.getElementById('canvas'); document.addEventListener('mousedown', function(event) { myTarget = event.target; alert('This is mousedown event.'); }, false); document.addEventListener('keydown', function(event) { if(myTarget == myCanvas) { alert('This is keydown event.'); } }, false); }
Advertisements