控制台:禁用Shift +方向键(文本选择模式)

是否可以在Windows控制台中为当前应用程序禁用文本选择模式?

With 'text selection mode', I mean that pressing Shift and an arrow key (e.g. Left) will be interpreted by the console host as a text selection comannd instead of being forwarded as a KeyPressedEvent to the running application.

I know that it is possible to disable the 'Quick Edit Mode' using the SetConsoleMode-function inside kernel32.dll:

[DllImport("kernel32.dll", SetLastError = true)]
static extern void* GetStdHandle(int nStdHandle);

[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(void* hWnd, ConsoleMode dwMode);

[DllImport("kernel32.dll")]
static extern bool GetConsoleMode(void* hWnd, ConsoleMode* lpMode);

[Flags]
public enum ConsoleMode
    : uint
{
    // ...
    ENABLE_QUICK_EDIT_MODE = 0x0040,
    // ...
}


static void DisableQEMode()
{
    void* ptr = GetStdHandle(-10);
    ConsoleMode mode;

    GetConsoleMode(ptr, &mode);
    SetConsoleMode(ptr, mode & ~ConsoleMode.ENABLE_QUICK_EDIT_MODE);
}

但是,这不能解决我的问题。按键输入Shift + Left仍不会转发到我的应用程序。

我是否错过了设置其他控制台标志的机会?

(我的应用程序是用C#编写的,但是我也可以使用C ++解决方案。)

评论