Reputation: 146180
For debugging purposes I sometimes check to see if ctrl key is held down for special 'secret' actions. I may do this in an arbitrary function that isn't necessary an event handler itself (it may be a callback from something or it may be an event handler).
I've been using the following in typescript:
if (window.event.ctrlKey)
Suddenly now with Visual Studio 2015 RTM (I assume this is TS 1.5) this is not allowed due to ctrlKey
not being in the event
object anymore.
I'm not sure why and I'm more curious than anything. Is it safe to add it back? Why was it taken away?
[As an aside it turns out this probably doesn't work in Firefox anyway so I'm also looking for a complete cross platform solution]
Upvotes: 3
Views: 1946
Reputation: 276235
You can easily add that to the interface yourself. e.g. the following code does this :
interface Event{
ctrlKey : boolean;
}
if (window.event.ctrlKey){
}
Checkout the docs on lib.d.ts
: http://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html
That said its better if you use a type assertion :
if ((<KeyboardEvent>window.event).ctrlKey){
}
Checkout the docs on type assertions : http://basarat.gitbooks.io/typescript/content/docs/types/type-assertion.html
Upvotes: 3