feat: add actual code and update README.md

This commit is contained in:
Jason Fraley 2026-11-17 15:35:27 +00:00 committed by Jason Fraley
commit d3e3b43c0f
3 changed files with 189 additions and 0 deletions

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2026 jason
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

38
README.md Normal file
View file

@ -0,0 +1,38 @@
# WinXKill
<<<<<<< HEAD
A Windows take on KDE's Ctrl+Alt+Esc "kill window" mode, written for AutoHotkey v2
=======
A Windows take on KDE's Ctrl+Alt+Esc "kill window" mode, written for AutoHotkey v2.
## Install
1. Install AutoHotkey v2 (tested with 2.0.26).
2. Keep `WinXKill.ahk` in `C:\Users\jason.fraley\Tools\WinXKill`.
3. Double-click `WinXKill.ahk` to start it. A tray icon appears.
## Use
- Press **Ctrl+Alt+Esc** in any app to turn on kill mode. The cursor changes to a crosshair, and a tooltip
names the window under it (process name, PID, title).
- **Left-click** a window to end its whole process (not just close the window). Kill mode then turns off.
- Press **Esc** or **right-click** to cancel without killing anything.
- Tray menu: **Enter kill mode** and **Exit**.
## Autostart
A shortcut at `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\WinXKill.lnk` runs
`AutoHotkey64.exe "C:\Users\jason.fraley\Tools\WinXKill\WinXKill.ahk"` when you sign in.
Delete the shortcut to turn autostart off.
## Limitations
- The script refuses to kill `explorer.exe` (desktop, taskbar and File Explorer windows) and itself.
- It runs unelevated and never asks for UAC. It can't end elevated (administrator) processes. When a kill fails,
a tray notification and tooltip say so.
- Clicking a window ends every window that belongs to the same process (for example, all windows of a browser).
Unsaved work is lost.
- Crash recovery: if the script is ended while kill mode is on, the crosshair cursor may stay. Sign out, or change
the pointer scheme in Settings, to restore the normal cursors.
- Optional: start the script with `/debug` to write a log to `%TEMP%\WinXKill-debug.log`.
>>>>>>> 3a587b0 (Initial commit)

142
WinXKill.ahk Normal file
View file

@ -0,0 +1,142 @@
; WinXKill - KDE-style "kill window" mode for Windows (AutoHotkey v2)
; Ctrl+Alt+Esc enters kill mode. Left-click a window to end its process.
; Esc or right-click cancels.
#Requires AutoHotkey v2.0
#SingleInstance Force
Persistent
global KillMode := false
global SelfPID := ProcessExist()
global ProtectedExes := Map("explorer.exe", 1, "winxkill.exe", 1)
global ShellClasses := Map("Shell_TrayWnd", 1, "Shell_SecondaryTrayWnd", 1, "Progman", 1, "WorkerW", 1)
A_IconTip := "WinXKill - Ctrl+Alt+Esc to kill a window"
try TraySetIcon("shell32.dll", 132)
A_TrayMenu.Delete()
A_TrayMenu.Add("Enter kill mode`tCtrl+Alt+Esc", (*) => EnterKillMode())
A_TrayMenu.Add()
A_TrayMenu.Add("Exit", (*) => ExitApp())
A_TrayMenu.Default := "Enter kill mode`tCtrl+Alt+Esc"
OnExit((*) => RestoreCursors())
$^!Esc:: EnterKillMode()
#HotIf KillMode
*LButton:: KillUnderCursor()
*RButton:: LeaveKillMode("Cancelled")
*Esc:: LeaveKillMode("Cancelled")
*LButton Up:: return
*RButton Up:: return
#HotIf
EnterKillMode() {
global KillMode
if KillMode
return
KillMode := true
SetCrossCursor()
Log("enter kill mode")
SetTimer(UpdateTip, 50)
}
LeaveKillMode(msg := "") {
global KillMode
KillMode := false
SetTimer(UpdateTip, 0)
ToolTip()
RestoreCursors()
Log("leave kill mode " msg)
if (msg != "") {
ToolTip(msg)
SetTimer(() => ToolTip(), -1500)
}
}
GetTarget(&hwnd, &pid, &exe, &title, &cls) {
MouseGetPos(, , &hwnd)
pid := 0, exe := "", title := "", cls := ""
if !hwnd
return false
try {
pid := WinGetPID(hwnd)
exe := WinGetProcessName(hwnd)
title := WinGetTitle(hwnd)
cls := WinGetClass(hwnd)
}
return true
}
IsProtected(pid, exe, cls) {
return pid = 0 || pid = SelfPID || ShellClasses.Has(cls)
|| ProtectedExes.Has(StrLower(exe)) || pid = 4
}
ShowTip(text) {
static last := ""
CoordMode("Mouse", "Screen"), CoordMode("ToolTip", "Screen")
MouseGetPos(&mx, &my)
ToolTip(text, mx + 24, my + 24)
if (text != last)
Log("tip: " StrReplace(text, "`n", " | ")), last := text
}
Log(msg) {
static on := (A_Args.Length && A_Args[1] = "/debug")
if on
FileAppend(FormatTime(, "HH:mm:ss") " " msg "`n", A_Temp "\WinXKill-debug.log")
}
UpdateTip() {
if !GetTarget(&hwnd, &pid, &exe, &title, &cls) {
ShowTip("KILL MODE: no window")
return
}
t := StrLen(title) > 60 ? SubStr(title, 1, 57) "..." : title
if IsProtected(pid, exe, cls)
ShowTip("KILL MODE (protected): " exe " - " t "`nEsc / right-click to cancel")
else
ShowTip("KILL MODE: click to kill`n" exe " (PID " pid ")`n" t "`nEsc / right-click to cancel")
}
KillUnderCursor() {
SetTimer(UpdateTip, 0)
ToolTip()
Sleep 30
ok := GetTarget(&hwnd, &pid, &exe, &title, &cls)
Log("click: hwnd=" hwnd " pid=" pid " exe=" exe " class=" cls " title=" title)
if !ok || IsProtected(pid, exe, cls) {
LeaveKillMode()
Log("refused (protected)")
Notify("Not killed", (exe != "" ? exe : "That window") " is protected (desktop/taskbar/WinXKill).")
return
}
LeaveKillMode()
ProcessClose(pid)
if ProcessWaitClose(pid, 2) {
Log("kill FAILED pid=" pid)
Notify("Could not kill " exe, "PID " pid " is still running. It is probably elevated (run as administrator); WinXKill runs unelevated and cannot end it.")
return
}
Log("killed pid=" pid)
ToolTip("Killed " exe " (PID " pid ")")
SetTimer(() => ToolTip(), -1500)
}
Notify(title, text) {
TrayTip(text, "WinXKill: " title, 0x2)
ToolTip(title ": " text)
SetTimer(() => ToolTip(), -4000)
}
SetCrossCursor() {
static ids := [32512, 32513, 32514, 32515, 32516, 32642, 32643, 32644, 32645, 32646, 32648, 32649, 32650, 32651]
cross := DllCall("LoadCursor", "Ptr", 0, "Ptr", 32515, "Ptr")
for id in ids {
copy := DllCall("CopyImage", "Ptr", cross, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
DllCall("SetSystemCursor", "Ptr", copy, "UInt", id)
}
}
RestoreCursors() {
DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 0, "Ptr", 0, "UInt", 0) ; SPI_SETCURSORS
}