Skip to content Skip to sidebar Skip to footer

Turn Off Windows 10 Console "mark" Mode From My Application

I've got a console application written in Python. Windows 10 console's 'Mark' mode is frustrating me to no end as users accidentally click in the application while doing something

Solution 1:

Automatic "Mark" mode using the mouse in windows 10, is "Quick Edit" mode from prior versions. I believe the only difference is that it is now on by default. Quick Edit Mode can be enabled/disabled from code:

import time
import win32console

ENABLE_QUICK_EDIT_MODE = 0x40
ENABLE_EXTENDED_FLAGS = 0x80defquick_edit_mode(turn_on=None):
    """ Enable/Disable windows console Quick Edit Mode """
    screen_buffer = win32console.GetStdHandle(-10)
    orig_mode = screen_buffer.GetConsoleMode()
    is_on = (orig_mode & ENABLE_QUICK_EDIT_MODE)
    if is_on != turn_on and turn_on isnotNone:
        if turn_on:
            new_mode = orig_mode | ENABLE_QUICK_EDIT_MODE
        else:
            new_mode = orig_mode & ~ENABLE_QUICK_EDIT_MODE
        screen_buffer.SetConsoleMode(new_mode | ENABLE_EXTENDED_FLAGS)

    return is_on if turn_on isNoneelse turn_on

quick_edit_enabled = quick_edit_mode()
whileTrue:
    print('Quick edit is %s' % ('on'if quick_edit_enabled else'off'))
    time.sleep(3)
    quick_edit_enabled = quick_edit_mode(not quick_edit_enabled)

Solution 2:

I'm a little short on reputation to comment on Stephen's answer so I'm posting a separate answer.

To make this multi-platform/environment friendly add some conditional checks to skip over the code when not running on windows or when no console is attached to the process such as when running inside an IDE or when built via pyinstaller etc:

if os.name == "nt" and sys.stdout.isatty():
    # stephen's code here...

This prevents errors from being raised in several cases. In my opinion you should also add a try/catch-all around the code block since os-implementations of the methods involved are unknown and are known to raise exceptions and be finicky. In the worst case scenario I would rather my code continue to run with QuickEdit enabled than fail because of it.

Post a Comment for "Turn Off Windows 10 Console "mark" Mode From My Application"