From afa2ad17231a499bc0538155720b4847a103c564 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Thu, 15 Aug 2019 13:35:44 -0700 Subject: [PATCH] Updated behavior so VkKeyScan codes outside of the range 0-255 are ignored, fixing a crash in powershell --- modules/win-terminal.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/win-terminal.js b/modules/win-terminal.js index 81ce24d..d5e1e10 100644 --- a/modules/win-terminal.js +++ b/modules/win-terminal.js @@ -397,7 +397,11 @@ function windows_terminal() { } } } - this._WriteCharacter = function (key, bControlKey) { + this._WriteCharacter = function (key, bControlKey) + { + var scanCode = this._user32.VkKeyScanA(key).Val; + if (scanCode < 0 || scanCode > 255) { return; } + var rec = GM.CreateVariable(20); rec.Deref(0, 2).toBuffer().writeUInt16LE(KEY_EVENT); // rec.EventType rec.Deref(4, 4).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.bKeyDown @@ -405,11 +409,11 @@ function windows_terminal() { rec.Deref(14, 1).toBuffer()[0] = key; // rec.Event.KeyEvent.uChar.AsciiChar rec.Deref(8, 2).toBuffer().writeUInt16LE(1); // rec.Event.KeyEvent.wRepeatCount rec.Deref(10, 2).toBuffer().writeUInt16LE(this._user32.VkKeyScanA(key).Val); // rec.Event.KeyEvent.wVirtualKeyCode - rec.Deref(12, 2).toBuffer().writeUInt16LE(this._user32.MapVirtualKeyA(this._user32.VkKeyScanA(key).Val, MAPVK_VK_TO_VSC).Val); - + rec.Deref(12, 2).toBuffer().writeUInt16LE(this._user32.MapVirtualKeyA(scanCode, MAPVK_VK_TO_VSC).Val); + var dwWritten = GM.CreateVariable(4); if (this._kernel32.WriteConsoleInputA(this._stdinput, rec, 1, dwWritten).Val == 0) { return (false); } - + rec.Deref(4, 4).toBuffer().writeUInt16LE(0); // rec.Event.KeyEvent.bKeyDown return (this._kernel32.WriteConsoleInputA(this._stdinput, rec, 1, dwWritten).Val != 0); }