Detecting keypress in Google Maps

google-maps, google-maps-api-3, keyboard-events

Solution

You can disable the keyboard shortcuts in Google Maps like here

https://developers.google.com/maps/documentation/javascript/reference?hl=en#MapOptions

and then you can use the keyboard shortcuts for your own purposes.

Problem

Is there a way to detect keypress only when the Google Maps canvas is in focus? Google Maps JavaScript API V3 has built-in keyboard shortcuts. When a user clicks on a map tile or drags it, the map becomes in focus, and will respond to keyboard shortcuts. If you click anywhere else outside the map canvas, those keyboard shortcuts will no longer work. I would like to extend some of these shortcuts (specifically the arrow keys) to perform additional actions.

Original source