А почему Django а не Flask?
И это же бэкэнд, почему PHP или какие-нибудь фреймворки для JS не подойдут?
import ctypes
from ctypes import wintypes
import time
import os
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32
psapi = ctypes.windll.psapi
MAX_PATH = 256
PROCESS_QUERY_INFORMATION = 0x0400
def process_name(h_wnd):
pid = wintypes.DWORD()
user32.GetWindowThreadProcessId(h_wnd, ctypes.byref(pid))
process = kernel32.OpenProcess(PROCESS_QUERY_INFORMATION, False, pid)
filename = None
if process:
path = ctypes.create_unicode_buffer(MAX_PATH)
if psapi.GetProcessImageFileNameW(process, path, MAX_PATH) > 0:
filename = os.path.basename(path.value)
kernel32.CloseHandle(process)
return filename
while True:
h_wnd = user32.GetForegroundWindow()
filename = process_name(h_wnd)
print(filename)
time.sleep(1)