How to disable user selection in Windows console

2020-04-17 05:00发布

I need to disable user mouse selection in the Windows console. Is it possible and how? I tried the function SetConsoleMode() to disable mouse input with it, but it did not work as I expected. Selecting was still possible.

1条回答
Luminary・发光体
2楼-- · 2020-04-17 05:25

The console's quick-edit mode allows the user to quickly select and copy text using the mouse, without having to first enter mark mode (i.e. Ctrl+M, or Edit -> Mark on the menu). It's usually convenient to enable quick-edit mode, but it does interfere with getting mouse input. You can disable it using a handle for the console input buffer as follows:

DWORD prev_mode;
GetConsoleMode(hInput, &prev_mode); 
SetConsoleMode(hInput, ENABLE_EXTENDED_FLAGS | 
    (prev_mode & ~ENABLE_QUICK_EDIT_MODE));

Remember to restore the previous mode at exit.

查看更多
登录 后发表回答