{"record":{"id":"236802a817e16b08","repo":"tui-cs/Terminal.Gui","slug":"failed-to-set-input-console-mode-error-code-get","errorCode":null,"errorMessage":"Failed to set input console mode, error code: {GetLastError()}.","messagePattern":"Failed to set input console mode, error code: (.+?)\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"critical","filePath":"Terminal.Gui/Drivers/WindowsHelpers/NetWinVTConsole.cs","lineNumber":53,"sourceCode":"\n    public NetWinVTConsole ()\n    {\n        _inputHandle = GetStdHandle (STD_INPUT_HANDLE);\n\n        if (!GetConsoleMode (_inputHandle, out uint mode))\n        {\n            throw new ApplicationException ($\"Failed to get input console mode, error code: {GetLastError ()}.\");\n        }\n\n        _originalInputConsoleMode = mode;\n\n        if ((mode & ENABLE_VIRTUAL_TERMINAL_INPUT) == 0)\n        {\n            mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;\n\n            if (!SetConsoleMode (_inputHandle, mode))\n            {\n                throw new ApplicationException ($\"Failed to set input console mode, error code: {GetLastError ()}.\");\n            }\n        }\n\n        _outputHandle = GetStdHandle (STD_OUTPUT_HANDLE);\n\n        if (!GetConsoleMode (_outputHandle, out mode))\n        {\n            throw new ApplicationException ($\"Failed to get output console mode, error code: {GetLastError ()}.\");\n        }\n\n        _originalOutputConsoleMode = mode;\n\n        if ((mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0)\n        {\n            mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;\n\n            if (!SetConsoleMode (_outputHandle, mode))\n            {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/tui-cs/Terminal.Gui/blob/2e47b11478db083499917f2ad27c34d30efb0df1/Terminal.Gui/Drivers/WindowsHelpers/NetWinVTConsole.cs#L35-L71","documentation":"This error is thrown by the NetWinVTConsole constructor when SetConsoleMode fails while attempting to add ENABLE_VIRTUAL_TERMINAL_INPUT to the input console mode. This happens when the current input mode does not already have VT input enabled and the OS rejects the attempt to enable it. The GetLastError code indicates why the OS refused.","triggerScenarios":"Thrown at NetWinVTConsole.cs:53 when (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) == 0 and the subsequent SetConsoleMode(_inputHandle, mode | ENABLE_VIRTUAL_TERMINAL_INPUT) returns false. This is a Windows 10+ feature; older OS versions or locked-down consoles reject the flag.","commonSituations":"Running on Windows versions prior to 1709 (Threshold 2 / pre-Anniversary Update), running under a locked-down kiosk or restricted console session, third-party terminal interceptors that wrap the console handle, or group policy disabling VT input.","solutions":["Upgrade to Windows 10 version 1709 or later where ENABLE_VIRTUAL_TERMINAL_INPUT is natively supported.","Check for terminal-interception software (e.g., wrapper tools) and disable them.","If on an older system, select the legacy WindowsDriver input path (non-VT) instead of the VT helper.","Verify the console host is conhost.exe / Windows Terminal and not a custom replacement that does not support the VT input flag."],"exampleFix":"// before -- default driver selection hits VT input on unsupported OS\nusing IApplication app = Application.Create().Init();\n\n// after -- force the legacy Windows driver on older Windows\nApplication.ForceDriver = \"Windows\";\nusing IApplication app = Application.Create().Init();","handlingStrategy":"validation","validationCode":"// Check Windows version supports VT input\nif (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 16299)) { /* VT input supported */ }\nelse { Application.ForceDriver = \"Windows\"; /* use legacy driver */ }","typeGuard":null,"tryCatchPattern":"try { using IApplication app = Application.Create().Init(); app.Run<MyWindow>(); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"set input console mode\"))\n{ Application.ForceDriver = \"Windows\"; /* retry with legacy */ }","preventionTips":["Upgrade to Windows 10 1709+ for ENABLE_VIRTUAL_TERMINAL_INPUT support.","Force the legacy WindowsDriver on older Windows via Application.ForceDriver = \"Windows\".","Disable third-party console interceptors that may block VT input.","Check for group policy disabling VT input features."],"tags":["windows","console","driver","win32","input","initialization"],"backgroundTag":null,"analyzedSha":"2e47b11478db083499917f2ad27c34d30efb0df1","analyzedAt":"2026-08-13T19:20:08.826Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}