Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  151] [ 3]  / answers: 1 / hits: 38544  / 8 Years ago, fri, july 29, 2016, 12:00:00

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.


More From » typescript

 Answers
28

This



window.addEventListener('keydown', keyDownListener, false)


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
}

[#61206] Wednesday, July 27, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
payne

Total Points: 527
Total Questions: 108
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;