Posts

Showing posts with the label Escaping

Batch Character Escaping

Answer : This is adapted with permission of the author from the page Batch files - Escape Characters on Rob van der Woude's Scripting Pages site. TLDR Windows (and DOS) batch file character escaping is complicated: Much like the universe, if anyone ever does fully come to understand Batch then the language will instantly be replaced by an infinitely weirder and more complex version of itself. This has obviously happened at least once before ;) Percent Sign % % can be escaped as %% – "May not always be required [to be escaped] in doublequoted strings, just try" Generally, Use a Caret ^ These characters "may not always be required [to be escaped] in doublequoted strings, but it won't hurt": ^ & < > | Example: echo a ^> b to print a > b on screen ' is "required [to be escaped] only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used" ` is "required [to be es...

Angular 2 HostListener Keypress Detect Escape Key?

Answer : Try it with a keydown or keyup event to capture the Esc key. In essence, you can replace document:keypress with document:keydown.escape : @HostListener('document:keydown.escape', ['$event']) onKeydownHandler(event: KeyboardEvent) { console.log(event); } It worked for me using the following code: const ESCAPE_KEYCODE = 27; @HostListener('document:keydown', ['$event']) onKeydownHandler(event: KeyboardEvent) { if (event.keyCode === ESCAPE_KEYCODE) { // ... } } or in shorter way: @HostListener('document:keydown.escape', ['$event']) onKeydownHandler(evt: KeyboardEvent) { // ... } Modern approach, event.key == "Escape" The old alternatives ( .keyCode and .which ) are Deprecated. @HostListener('document:keydown', ['$event']) onKeydownHandler(event: KeyboardEvent) { if (event.key === "Escape") { // Do things } }