current position:Home>Python solves the problem of suspending execution after clicking the mouse in CMD window (fast editing mode is prohibited)

Python solves the problem of suspending execution after clicking the mouse in CMD window (fast editing mode is prohibited)

2022-01-30 10:00:29 Shallow drunk cherry rain

problem

use Python Developed no interface program , The execution process is in cmd When printing information in a black window , Sometimes , Accidentally, the mouse clicks into the black window , The program hangs , No more execution , The focus must be removed to resume execution , It's very annoying . After some exploration, find a fairly simple solution , Write it down here , Share it with those in need .

Solution

Add these lines of code to the program to be executed .

import ctypes

kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), 128)
 Copy code 

Want to know the meaning of parameters in detail , Please refer to the official documents of Microsoft docs.microsoft.com/en-us/windo….

This solution refers to the description of these two attribute values : Insert picture description here

copyright notice
author[Shallow drunk cherry rain],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201301000261131.html

Random recommended