Handler for CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT
Project description
handler for CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT
Tested against Windows 10 / Python 3.11 / Anaconda
pip install consolectrlhandler
Console Control Handler for Windows
This module provides functionality for handling console control events in Windows,
namely CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT
Args:
ctrl_type (int): The type of control event.
Returns:
bool: True if the event is handled; False otherwise.
Example:
To use this module, import it and set your desired function as the console handler:
>>> from consolectrlhandler import ctrl_config
Define your custom function to handle console control events:
>>> def ctrl_handler(ctrl_type):
... print(f"Received control event: {ctrl_type}")
Assign your custom function as the console handler:
>>> ctrl_config.function = ctrl_handler
Then run your main program loop.
# Complete code
from consolectrlchandler import ctrl_config
import time
def ctrlhandler(ctrl_type):
print(f"ctrl handler {ctrl_type}")
ctrl_config.function = ctrlhandler
while True:
print("test")
time.sleep(1)
test
test
ctrl handler 0
test
ctrl handler 0
ctrl handler 0
ctrl handler 0
ctrl handler 0
test
ctrl handler 0
test
test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for consolectrlchandler-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51503e2caadf0f2862d420a6f3f9e59236cf9d9cd3b243e83db20201dbd717cd |
|
MD5 | 3442529b219edfcedb96e187da09d8dc |
|
BLAKE2b-256 | 13bbe34a8d8e71138acb8bd20cb61c4856831386c48b0aeaa5011b04cdc666ee |