script to open an image, depending on your active program problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
autohotkeycool
Posts: 137
Joined: 24 May 2016, 08:23

script to open an image, depending on your active program problem

07 May 2021, 15:33

Im currently trying to use this script to open a specific image based on the program my mouse Is hovering over [eg if im hovering over “winword.exe” it should open “word.png” – but the problem is nothing happens when I do press the hotkey win+A – any idea whats wrong with the script?

Code: Select all

#a:: ; Win + A
    MouseGetPos,,, Hwnd
    WinGet, PN, ProcessName, % "ahk_id " Hwnd
    Msgbox % "Process name: " PN
    If (PN = "WINWORD.EXE")                                                        ; Specify the window title here.
    {
        Gui, +AlwaysOnTop
        Gui, Add, Pic, xm ym, C:\Users\user\OneDrive\Pictures\Hotkeys\Keyboard Hotkeys\Word.png
        Gui, Show
    }
    WinActivate % "ahk_id " Hwnd
Return

GuiClose:
ExitApp
LeSeb
Posts: 17
Joined: 25 Oct 2017, 14:50

Re: script to open an image, depending on your active program problem

07 May 2021, 15:45

Hello,

I just tested with notepad as the used process and it works :?
digidings
Posts: 24
Joined: 22 Jan 2018, 17:04

Re: script to open an image, depending on your active program problem

07 May 2021, 15:46

Perhaps this hotkey is used another program, so first try another hotkey e.g. F12,
You should at least see the MsgBox "Hotkey triggered"
Try to find the mistake in the path to your picture, like this:

Code: Select all

WordPicPath := "C:\Users\user\OneDrive\Pictures\Hotkeys\Keyboard Hotkeys\Word.png"
if (!FileExist(WordPicPath))
    MsgBox % "Can't find file WordPicPath = " . WordPicPath  
    
F12::
#a:: ; Win + A
    MouseGetPos,,, Hwnd
    WinGet, PN, ProcessName, % "ahk_id " Hwnd
    Msgbox % "Process name: " PN
    If (PN = "WINWORD.EXE")                                                        ; Specify the window title here.
    {
        Gui, +AlwaysOnTop
        Gui, Add, Pic, xm ym, % WordPicPath 
        Gui, Show
    }
    WinActivate % "ahk_id " Hwnd
    MsgBox Hotkey triggered
Return

GuiClose:
ExitApp
autohotkeycool
Posts: 137
Joined: 24 May 2016, 08:23

Re: script to open an image, depending on your active program problem

07 May 2021, 17:47

Thanks folks

if I wanted to make the image opened by a certain program what changed would you reocvmmend to the script? E.g. I'd like it to be opened by a program in folder

C:\PortableApps Platform\PortableApps\XnViewMP\xnviewmp.exe
autohotkeycool
Posts: 137
Joined: 24 May 2016, 08:23

Re: script to open an image, depending on your active program problem

08 May 2021, 06:59

Code: Select all

#a:: ; Win + A
    MouseGetPos,,, Hwnd
    WinGet, PN, ProcessName, % "ahk_id " Hwnd
    Msgbox % "Process name: " PN
    If (PN = "WINWORD.EXE")                                                        ; Specify the window title here.
    {
        Gui, +AlwaysOnTop
        Gui, Add, Pic, xm ym, C:\Users\user\OneDrive\Pictures\Hotkeys\Keyboard Hotkeys\Word.png
        Gui, Show
    }
    WinActivate % "ahk_id " Hwnd
Return

GuiClose:
ExitApp
E.g. Where should I add the "C:\PortableApps Platform\PortableApps\XnViewMP\xnviewmp.exe" so that the "word.png" image will be opened by xnviewmp.exe?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 337 guests