I want to take key press event, ut this is not on specific field, its on page/window.

Example:  

While doing automation, on web page I have short-cut key suppose `M` (keyboard key). So how should I achieve this? If it can be achieved by inserting a JavaScript then how can I write it? I'm beginner in JavaScript.