如何在Windows控制台中禁用用户选择 [英] How to disable user selection in Windows console
问题描述
我需要在Windows控制台中禁用用户鼠标选择。有可能吗?我尝试使用功能 SetConsoleMode()
禁用鼠标输入,但是它没有按预期工作。仍然可以选择。
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.
推荐答案
控制台的快速编辑模式允许用户使用鼠标快速选择和复制文本,而无需使用鼠标。必须先进入标记模式(即 Ctrl + M 或菜单上的Edit-> Mark)。启用快速编辑模式通常很方便,但确实会干扰鼠标的输入。您可以使用控制台输入缓冲区的句柄来禁用它,如下所示:
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.
这篇关于如何在Windows控制台中禁用用户选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!