How to detect any key press in Angular 2?
<p>How do I detect any key press on Angular 2 (e.g. not necessarily in an input box)</p>

<p>Currently I managed to do this using the following code:</p>

<pre><code>import {Component, HostListener} from "@angular/core";

@Component(&lt;any&gt;{
    selector: 'foo',
    template: `&lt;h1&gt;Foo&lt;/h1&gt;`,
})
export class FooComponent {
    @HostListener('document:keypress', ['$event'])
    keypress(e: KeyboardEvent) {
        console.log("Key Up! " + e.key);
    }
}
</code></pre>

<p>The above code manages to work fine for most characters e.g. alphanumeric, punctuation, symbols, etc</p>

<p>The issue is that this method does not run when pressing keys such as SHIFT, CTRL, F1...F12, Tab, ALT etc.</p>