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 consolectrlchandler
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
File details
Details for the file consolectrlchandler-0.11.tar.gz
.
File metadata
- Download URL: consolectrlchandler-0.11.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92942110a4f70ef64e61aae771bf8fbf4a66a09beb16efd5ba42ca91260eba57 |
|
MD5 | e4d453d5d4a9f70c535d672f21bcb5a2 |
|
BLAKE2b-256 | 27e2a4b5fa2ae21e823e09fa527ade0c07f8d55d375e1d272fa9eb3a5a1fa866 |
File details
Details for the file consolectrlchandler-0.11-py3-none-any.whl
.
File metadata
- Download URL: consolectrlchandler-0.11-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e905dd9a5bda146d3847b48ffb47e31e58e69d5f2887e8ea0158d2f715fc115b |
|
MD5 | 3f67a9f818583dc0a7fd764a68f88210 |
|
BLAKE2b-256 | f80c2bdf279f7890dfc66360177fdd68f3a7637970211fb8a9b5a5626018cecd |