Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

consolectrlchandler-0.10.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

consolectrlchandler-0.10-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page