How to read the keyboard and mouse events in a window

I am just a beginner in front end development i will explain my problem

i wand to read the keyboard event happening in a window which i opened.
for an example consider the online or html5 game running in a browser we are giving the input by opening that page and window is reading the input like keyboard events mouse events and position of mouse in the window , what ever input we are giving to that window.

it is not like we are give input to the form input box

can any one share there knowledge/tutorials/more details to solver this problem.

Maybe a hidden input, and then on the event of keyUp?

Something like:

document.addEventListener("onKeyUp", e => {

Hey there,

this is what DOM events are for.

You can find a list of DOM events here: