Ruby ruby GetStdHandle 如何关闭快速编辑模式 ?

sevk · December 13, 2021 · Last by rosabella replied at January 02, 2024 · 292 hits
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);

DWORD mode;

GetConsoleMode(hStdin, &mode);

mode &= ~ENABLE_QUICK_EDIT_MODE; //移除快速编辑模式

mode &= ~ENABLE_INSERT_MODE; //移除插入模式

mode &= ~ENABLE_MOUSE_INPUT;

SetConsoleMode(hStdin, mode);

我想把这个代码写成 Ruby 的,但是 GetStdHandle 的参数 STD_INPUT_HANDLE 是多少?查了半天,没找到. 有其它办法吗?

用 C 语言暂时解决了问题:

disable_quick_edit.cpp :

#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;

int main(){
    HANDLE hInput;
    DWORD prev_mode;
    hInput = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hInput, &prev_mode); 
    SetConsoleMode(hInput, prev_mode & ENABLE_EXTENDED_FLAGS);
    return 0;
}

编译命令:

cd /d C:\Program Files\Microsoft Visual Studio 10.0\VC

vcvarsall.bat

cl.exe /EHsc  disable_quick_edit.cpp

得到 disable_quick_edit.exe , 执行一下这个 31 KB 的 exe 就行。

foodle, A must-read that teaches important lessons. This is quite helpful, so please accept my gratitude.

@pooh in korea The I think the "hInput = GetStdHandle(STD_INPUT_HANDLE);" is incorrect. Or at least it does not work for me.

We learned useful things from your blog that we can use. Your post has a lot of great tips Happy wheels.

You need to Sign in before reply, if you don't have an account, please Sign up first.