Autohotkey script for alt+F4

0

I need a way to create a shortcut icon on the Desktop that when clicked, emulates the press of ALT+F4. I was thinking at AutoHotKey, I have bound the alt+f4 combination to F12, but then I can't manage to send the keystroke automatically. I want that when I run the script, it emulates Alt+F4 and then close itself. I don't know if there is a better way, I'm open to any solution

Thanks

Ponzaro

Posted 2016-06-28T17:39:31.880

Reputation: 23

Answers

1

WinGet, id, list
Loop, %id%
{
    this_ID := id%A_Index%
    If NOT IsWindow(WinExist("ahk_id" . this_ID))
        continue
    WinClose, ahk_id %this_ID%
        break
}
return

; This checks if a window is, in fact a window.
; As opposed to the desktop or a menu, etc.
IsWindow(hwnd){
   WinGet, s, Style, ahk_id %hwnd%
   return s & 0xC00000 ? (s & 0x100 ? 0 : 1) : 0
}

user3419297

Posted 2016-06-28T17:39:31.880

Reputation: 2 055

It works flawlessly – Ponzaro – 2016-06-29T21:47:46.507

0

Just write a one line script that sends Alt-F4. But I'm assuming you want to shutdown downs? Why not use the Shutdown command - DOC: https://autohotkey.com/docs/commands/Shutdown.htm

You can also use the regular shutdown command that https://stackoverflow.com/questions/162304/how-do-i-shutdown-restart-logoff-windows-via-a-bat-file

lintalist

Posted 2016-06-28T17:39:31.880

Reputation: 258

No, I want to close the active window, I don't want to shutdown :) – Ponzaro – 2016-06-28T20:09:29.413

1There is a command for that as well, WinClose. But I don't see how that would work, if you click the desktop, the desktop becomes the active window and closing the desktop closes Windows (the OS, not the "window" what was active before you clicked the desktop). – lintalist – 2016-06-28T20:38:05.300