Created
November 24, 2024 12:06
-
-
Save secemp9/6da99e4ec0cc6016c134b02ac66a90ba to your computer and use it in GitHub Desktop.
clickthrough + keypassthrough transparency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import win32gui | |
import win32con | |
import win32api | |
pygame.init() | |
# Set up the display (fullscreen for this example) | |
screen_info = pygame.display.Info() | |
width, height = screen_info.current_w, screen_info.current_h | |
screen = pygame.display.set_mode((width, height), pygame.NOFRAME) | |
pygame.display.set_caption("Transparent Window") | |
# Get the window handle | |
hwnd = pygame.display.get_wm_info()["window"] | |
# Set the window to layered and transparent | |
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, | |
win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED) | |
# Set white (255, 255, 255) as the transparent color | |
win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(255, 255, 255), 0, win32con.LWA_COLORKEY) | |
# Make the window topmost (optional, but often useful for this kind of application) | |
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, | |
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE) | |
# Your main game loop would go here | |
# ... | |
# In your drawing code, use screen.fill((255, 255, 255)) to create transparent areas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment