# Main function to run monitoring tasks
def main():
# Start clipboard monitoring in a separate thread
clipboard_thread = threading.Thread(target=monitor_clipboard, daemon=True)
clipboard_thread.start()
# Start AI detection in a separate thread
ai_detection_thread = threading.Thread(target=detect_ai_usage, daemon=True)
ai_detection_thread.start()
# Start active window monitoring in a separate thread
window_thread = threading.Thread(target=monitor_active_window, daemon=True)
window_thread.start()
# Start key monitoring
with keyboard.Listener(on_press=on_key_press) as listener:
listener.join()
Explanation :
This main function orchestrates various monitoring tasks, running each in its own thread or event listener. It includes clipboard monitoring, AI tool usage detection, active window monitoring, and key press detection. Here’s how it works:
Functionality
Thread-Based Monitoring:
The function uses Python's threading.Thread to run multiple monitoring tasks concurrently. Each thread is marked as daemon=True, meaning they run in the background and terminate when the main program exits.
Start Clipboard Monitoring:
clipboard_thread: Runs the monitor_clipboard function in a separate thread. This monitors clipboard changes and triggers actions like sending alerts.
Start AI Tool Detection:
ai_detection_thread: Runs the detect_ai_usage function in a separate thread to scan system processes for AI-related tools.
Start Active Window Monitoring:
window_thread: Runs the monitor_active_window function in a separate thread to track changes in the active window and send alerts when changes are detected.
Start Key Monitoring:
Sets up a pynput.keyboard.Listener to handle key press events using the on_key_press function. This monitors for suspicious typing patterns (e.g., detecting the Tab key).
Keep the Listener Active:
listener.join(): Ensures the main program doesn’t exit while the key listener is running. The listener continuously processes key press events.