Skip to content

natejums/AlwaysOnTop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AlwaysOnTop

Two unfinished attempts at a Windows utility that would pin a window on top with a keyboard shortcut.

Neither one works. This repository is published as-is, from February 2023, as a record of the attempt. Read the next section before you try to run either file.

Why neither script works

AlwaysOnTop_windows.py (9 lines)

win32gui.EnumWindows(always_on_top, None)

EnumWindows walks every top-level window exactly once, synchronously, and then the process exits. The callback checks keyboard.is_pressed("ctrl + space") during that single instantaneous sweep, so unless the keys happen to be held down at the moment of launch, nothing is ever pinned — and if they were held, it would pin every window on the desktop rather than the focused one.

There is no hotkey listener and no event loop. A working version needs keyboard.add_hotkey (or a Win32 message loop) plus GetForegroundWindow to target one window.

It also imports win32gui, win32con (both from pywin32) and keyboard. Neither package is declared anywhere in this repo — there is no requirements.txt, setup.py, or pyproject.toml — so the usual result of running the file is an ImportError traceback.

Alwaysontop_powershell.ps1 (33 lines)

$keyboardHook = [System.Windows.Forms.KeyboardHook]::Start(...)

[System.Windows.Forms.KeyboardHook] does not exist in any version of .NET. The script dies on line 29 with a type-not-found error. A global hotkey in PowerShell needs RegisterHotKey from user32.dll via Add-Type, or a low-level WH_KEYBOARD_LL hook.

Two further problems:

  • Line 10 uses ContextMenu, which was removed in .NET Core 3.0 and later — so on PowerShell 7 it fails there first. (ContextMenuStrip is the replacement.)
  • The logic toggles TopMost on the NotifyIcon. A tray icon has no TopMost property and is not a window, so even with a working hotkey it would not pin anything.

Line 7 also calls ExtractAssociatedIcon on (Get-Process | Select-Object -First 1).Path, which is $null for system processes and throws non-fatally.

Requirements, if you want to experiment

Windows only. Both files use Windows-specific APIs and neither runs on macOS or Linux.

For the Python file:

pip install pywin32 keyboard

Note that keyboard requires administrator privileges on Windows to capture global input.

Status

Unmaintained. Kept for reference rather than use.

If you want to build a working version, the SetWindowPos(hwnd, HWND_TOPMOST, ...) call in the Python file is the correct primitive — that one line is sound. Everything around it needs replacing.

License

MIT — see LICENSE.

About

Two unfinished Windows scripts (Python + PowerShell) attempting a hotkey always-on-top utility. Neither works; published as-is from 2023.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages