Victor Rodriguez
Victor Rodriguez

Reputation: 21

Autohotkey winclose just wont work

I just want to have a simple function where Ctrl+F8 kills sublime text 3.

This is what i have so far, which doesn't work.

    ^F8::
    WinClose, "C:\Users\Eduardo\My Programs\Execs\Sublime Text 3\sublime_text.exe"
    return

I've also tried:

    ^F8::
    Winclose, Sublime Text 3
    return

and:

    ^F8::
    WinClose, Sublime Text
    return

Please help me with this. Ive looked at other examples and can't find what I am doing wrong.

Upvotes: 2

Views: 4017

Answers (1)

vasili111
vasili111

Reputation: 6930

WinClose command works with the window, not with the process. If you want to use WinClose command then you have to specify WinTitle and/or WinText of window you want to close. Also it is convenient to use SetTitleMatchMode command with WinClose. SetTitleMatchMode command sets the matching behavior of the WinTitle parameter of several commands, including WinClose. Particularly SetTitleMatchMode, 2 allows us to match not exact WinTitle for WinClose command. In that case a WinTitle can contain any part of actual WinTitle to be matched. Here is working example for notepad:

  SetTitleMatchMode, 2

  ^F8::
  WinClose, Notepad
  return

To work with process you can use Process command. Particularly, Process, close, notepad.exe will close notepad.exe process. Here is code:

  ^F8::
  Process, close, notepad.exe
  return

If my examples are not working for you:

  1. Use AutoHotkey and its documentation from http://ahkscript.org/ . You should always use AutoHotkey and its documenatation from http://ahkscript.org/ (current uptodate version, new official website)! AutoHotkey and its documentation from autohotkey.com is outdated and you may have some problems using them!

  2. Run it with administrator privileges.

  3. Make sure you saved script before running it.

Upvotes: 2

Related Questions