Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Normally when I wanted to catch an event on a page in js:
window.onkeydown = function (event) {
//Do something here
I cannot seem to figure out (or Google) how to do this in typescript. For the setup I am working in, there is a ts
file for the page, and a ts
file for the class that it is loading.
–
–
window
is defined will all events in lib.d.ts
and this particular listener as
addEventListener(type: "keydown", listener: (ev: KeyboardEvent) => any, useCapture?: boolean): void;
or this, if you want to keep your original "style",
window.onkeydown = (ev: KeyboardEvent): any => {
//do something
–
–
–
windows.addEventListener('keydown', (event: KeyboardEvent) =>{
// if you need event.code
windows.addEventListener('keydown', (event: Event) =>{
// event
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.