It's possible to disable the annoying QuickEdit Mode programmatically by importing Windows' Kernel32.dll library and using the console API functions GetStdHandle, GetConsoleMode, and SetConsoleMode through your language's native interface (e.g., Java's JNI, Python ctypes).
Python with ctypes:
Short (disables everything except EXTENDED_FLAGS). Read SetConsoleMode documentation for more detail.
import ctypes
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), 0x80)
Longer (disables QUICK_EDIT_MODE without altering other settings)
import ctypes
import time
import threading
# Constants
STD_INPUT_HANDLE = -10
# Enum for ConsoleModes
class ConsoleModes(ctypes.c_uint):
ENABLE_PROCESSED_INPUT = 0x1
ENABLE_LINE_INPUT = 0x2
ENABLE_ECHO_INPUT = 0x4
ENABLE_WINDOW_INPUT = 0x8
ENABLE_MOUSE_INPUT = 0x10
ENABLE_INSERT_MODE = 0x20
ENABLE_QUICK_EDIT_MODE = 0x40
ENABLE_EXTENDED_FLAGS = 0x80
ENABLE_AUTO_POSITION = 0x100
# Import kernel32.dll functions
kernel32 = ctypes.windll.kernel32
GetStdHandle = kernel32.GetStdHandle
GetConsoleMode = kernel32.GetConsoleMode
SetConsoleMode = kernel32.SetConsoleMode
def disable_quick_edit_mode():
std_in = GetStdHandle(STD_INPUT_HANDLE)
mode = ctypes.c_uint()
if GetConsoleMode(std_in, ctypes.byref(mode)):
if mode.value & ConsoleModes.ENABLE_QUICK_EDIT_MODE:
mode.value ^= ConsoleModes.ENABLE_QUICK_EDIT_MODE
SetConsoleMode(std_in, mode)
def print_numbers():
i = 0
while True:
time.sleep(0.3)
print(i)
i += 1
def main():
disable_quick_edit_mode()
threading.Thread(target=print_numbers).start()
if __name__ == "__main__":
main()
Keep in mind that this code only runs on Windows. If you are writing software to be run on multiple operating systems, make sure to safeguard against errors.
Read More
C#:
Batch: