Skip to content

MBaranekTech/Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 

Repository files navigation

πŸ” Python Palindrome String

On Job Interview you can be asked for a palindrome string -> is a string that reads the same forwards and backwards
(racecar -> racecar).
Interviewers use this to test if you understand:
String manipulation (s[::-1], loops)
Data structures (lists, stacks, queues)
Python built-in functions

def isPalindrome(s):
  return s == s[::-1]

print(isPalindrome ("racecar"))

πŸ” Monitor Registry for Active Camera Use with Python Script

Windows tracks webcam access in the registry at:
no admin required

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged

Each app gets a subkey. If the LastUsedTimeStop value is 0, it means the app is currently using the camera.

πŸ“¦ Python Script to Detect Active Webcam Use

import winreg
import time

def is_camera_in_use():
    try:
        base_key_path = r"Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged"
        with winreg.OpenKey(winreg.HKEY_CURRENT_USER, base_key_path) as base_key:
            i = 0
            while True:
                try:
                    subkey_name = winreg.EnumKey(base_key, i)
                    with winreg.OpenKey(base_key, subkey_name) as subkey:
                        value, _ = winreg.QueryValueEx(subkey, "LastUsedTimeStop")
                        if value == 0:
                            return True
                    i += 1
                except OSError:
                    break
    except Exception as e:
        print(f"Error reading registry: {e}")
    return False

# 🟒 Main loop to monitor every 2 seconds
if __name__ == "__main__":
    print("Monitoring camera usage (Ctrl+C to stop)...")
    while True:
        if is_camera_in_use():
            print("πŸ“· Camera is currently in use!")
        else:
            print("βœ… Camera is not in use.")
            time.sleep(2)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published