DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Make script work only on specific apps?  (Read 6,640 times)

substep

  • Participant
  • Joined in 2010
  • *
  • Posts: 6
Make script work only on specific apps?
« on: August 13, 2010, 01:22 AM »
Right now this script excludes apps. I want to invert it so it will work only on selected apps (*.exe preferrably).
Code: (autohotkey)
SetTitleMatchMode, 2
~MButton::
ifwinactive ahk_class MozillaUIWindowClass
return
ifwinactive ahk_class Progman
    return
ifwinactive ahk_class Shell_TrayWnd
    return
ifwinactive ahk_class MozillaDialogClass
    return
ifwinactive ahk_class NotifyIconOverflowWindow
    return

Send !{F4}
Return

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Make script work only on specific apps?
« Reply #1 on: August 13, 2010, 01:30 AM »
Take a look at the #IfWinActive directive in AHK:

http://www.autohotkey.com/docs/commands/_IfWinActive.htm

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,840
    • Coding Snacks
Re: Make script work only on specific apps?
« Reply #2 on: August 13, 2010, 03:01 AM »
simply substitute the returns in your ifwinactive statements for the send routine (and of course you'll need to amend the AHK classes as appropriate)

Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

substep

  • Participant
  • Joined in 2010
  • *
  • Posts: 6
Re: Make script work only on specific apps?
« Reply #3 on: August 13, 2010, 03:27 PM »
Thx, now it's finished.
Code: (autohotkey)
SetTitleMatchMode, 2

#ifwinactive ahk_class TForm1
~MButton::
Send !{F4}
Return

#ifwinactive ahk_class TfrmStarter
~MButton::
Send !{F4}
Return

#ifwinactive ahk_class AkelPad4
~MButton::
Send !{F4}
Return

#ifwinactive ahk_class mp3DCWndClass
~MButton::
Send !{F4}
Return

#ifwinactive, Postbox
~MButton::
Send !{F4}
Return

#ifwinactive ahk_class XmainClass
~MButton::
Send !{F4}
Return

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: Make script work only on specific apps?
« Reply #4 on: August 13, 2010, 03:37 PM »
You can shorten it up a bit by using groups.

Code: (autohotkey)
SetTitleMatchMode, 2

GroupAdd, Alt_F4_Group, ahk_class TForm
GroupAdd, Alt_F4_Group, ahk_class TfrmStarter
GroupAdd, Alt_F4_Group, ahk_class AkelPad4
GroupAdd, Alt_F4_Group, ahk_class mp3DCWndClass
GroupAdd, Alt_F4_Group, ahk_class Postbox
GroupAdd, Alt_F4_Group, ahk_class XmainClass

#ifwinactive ahk_group Alt_F4_Group
~MButton::
Send !{F4}
Return

Original address: https://www.donationcoder.com/forum/index.php?topic=23720.0