Seeking Assistance: AutoHotkey Script for Picture-in-Picture Images with Custom Functions

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CoBon
Posts: 1
Joined: 30 May 2023, 17:10

Seeking Assistance: AutoHotkey Script for Picture-in-Picture Images with Custom Functions

Post by CoBon » 30 May 2023, 17:47

Hello AutoHotkey community,

I hope this message finds you well. I am currently working on an AutoHotkey script that involves displaying multiple images in a picture-in-picture style over a video game and implementing custom functions for clicking on each image. Unfortunately, I have encountered some difficulties, and I would greatly appreciate your assistance in resolving them.
My plan was to have each picture run a different macro in a video game whenever clicked on.

The script I have developed is as follows:

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent

; Set the coordinates for the images
Image1X := 10
Image1Y := 10
Image2X := 10
Image2Y := 120
Image3X := 10
Image3Y := 230
Image4X := 10
Image4Y := 340

; Load the images (replace with your file names)
Image1 := "First.png"
Image2 := "Second.png"
Image3 := "Third.png"
Image4 := "Fourth.png"

; Set the width and height for the images
ImageWidth := 100
ImageHeight := 100

; Create the GUI window
Gui, +AlwaysOnTop -Caption
Gui, Color, FFFFFF
Gui, Add, Picture, x%Image1X% y%Image1Y% w%ImageWidth% h%ImageHeight% hwndImage1, %Image1%
Gui, Add, Picture, x%Image2X% y%Image2Y% w%ImageWidth% h%ImageHeight% hwndImage2, %Image2%
Gui, Add, Picture, x%Image3X% y%Image3Y% w%ImageWidth% h%ImageHeight% hwndImage3, %Image3%
Gui, Add, Picture, x%Image4X% y%Image4Y% w%ImageWidth% h%ImageHeight% hwndImage4, %Image4%
Gui, Show, NA, Picture-in-Picture

; Set the transparency for the images
WinSet, TransColor, FFFFFF ; Set white as transparent color

Return

; Custom functions for each image
Image1:
    ; Function for Image1
    MsgBox, You clicked on Image 1.
Return

Image2:
    ; Function for Image2
    MsgBox, You clicked on Image 2.
Return

Image3:
    ; Function for Image3
    MsgBox, You clicked on Image 3.
Return

Image4:
    ; Function for Image4
    MsgBox, You clicked on Image 4.
Return
Here's a breakdown of what I think should happen:

1. The script creates a GUI window and adds picture controls for each image using the `Gui, Add, Picture` command.
2. The `hwnd` parameter in the `Gui, Add, Picture` command assigns a unique control ID (HWND) to each picture control. These control IDs are stored in variables (`Image1`, `Image2`, `Image3`, `Image4`) using the `hwnd` option.
3. The script sets the transparency color of the GUI window using `WinSet, TransColor` command. This makes the white color (FFFFFF) in the GUI window transparent.
4. When you click on an image, the script utilizes the `Control` command with the `Subscript` parameter to register a click event for each picture control. This allows the script to capture the click and perform a specific action.
5. The custom functions for each image (Image1, Image2, Image3, Image4) are defined after the `Return` statement in the script. These functions will be triggered when the corresponding image is clicked.
6. Inside each custom function, there is a function to show a message box, so a message box should appear.

The two specific issues I am facing include:

1. The images does not appear to be actually transparant, I would have expected any transparant sections of the images to display whatever is behind the window, instead it appears white.
2. Nothing happens when I click any of the images, I would have expected a message box to appear.

I have already attempted troubleshooting the script, but I have not been able to identify the root cause of the problems. I believe the issues may involve incorrect usage of certain commands.

If anyone in the community could spare some time to review my script and provide guidance or suggestions on how to rectify the mentioned issues, I would be immensely grateful.

Additionally, if there are any alternative approaches or best practices that could simplify the script or improve its functionality, I would be eager to learn about them, and I would be especially grateful for examples of their use.

Thank you in advance for your kind assistance. I truly appreciate the expertise and knowledge within this community.

Best regards,
CoBon

Return to “Ask for Help (v1)”