Switching .png files when mouse hovers over them

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Switching .png files when mouse hovers over them

15 Feb 2017, 12:09

Code: Select all

	Gui, 4:+Owner +AlwaysOnTop -Caption +Toolwindow +LastFound
	Gui, 4:Color, F0F0F0
	WinSet, TransColor, F0F0F0			
	WinSet, Transparent, 225
	WinSet, Region, 0-0 W420 H340 R45-45			
	Gui, 4:Add, Picture, x0 y0 w420 h340, HaloHosting.png
	Gui, 4:Add, Picture, x20 y25 Hidden BackgroundTrans gShowPlayers, ShowPlayers.png			
	Gui, 4:Add, Picture, x20 y25 BackgroundTrans gShowPlayers, ShowPlayers2.png
	Gui, 4:Add, Picture, x20 y85 BackgroundTrans gKickPlayer, KickPlayer.png
	Gui, 4:Add, Picture, x20 y85 Hidden BackgroundTrans gKickPlayer, KickPlayer2.png			
	Gui, 4:Add, Picture, x20 y145 BackgroundTrans gBanPlayer, BanPlayer.png
	Gui, 4:Add, Picture, x20 y145 Hidden BackgroundTrans gBanPlayer, BanPlayer2.png
	Gui, 4:Add, Picture, x20 y205 BackgroundTrans gUnbanPlayer, UnbanPlayer.png
	Gui, 4:Add, Picture, x20 y205 Hidden BackgroundTrans gUnbanPlayer, UnbanPlayer2.png			
	Gui, 4:Add, Picture, x20 y265 BackgroundTrans gResetMap, ResetMap.png
	Gui, 4:Add, Picture, x20 y265 Hidden BackgroundTrans gResetMap, ResetMap2.png			
 	Gui, 4:Show, W420 H340
 	MouseMove, 210, 50

I have written a script that I have been using with Halo Combat Evolved for about 4 years now. Everything has been working great. I have a window that pops up when I press the ' key above the Tab key. The ` key displays the Rcon command prompt that allows you to enter Halo commands during game play. For instance to display the players currently playing on your server. I used to have my script display a regular GUI window with buttons, but about 2 weeks ago I decided to try and make it display like the Halo menus. My problem is to make the mouse switch the .png files when I move the mouse cursor over them. As you can see in the code I have the ShowPlayers2.png which displays ("Show Players" with a light blue halo around it) as the default picture and the mouse cursor moving over the center of that picture. All of the .png files that have a 2 at the end of the file name have a light blue halo around the text. All of the .png files without a 2 at the end of the file name displays as light blue text on top of the GUI window. When I move the cursor over a picture with the plain text, for example move from "Show Players(ShowPlayers2.png) to "Kick Player"(KickPlayer.png), I need the script to hide both ShowPlayers2.png and KickPlayer.png and show ShowPlayers.png and KickPlayer2.png. This will give the mouse cursor the effect of switching from Show Players to Kick Player in the GUI window.
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Switching .png files when mouse hovers over them

15 Feb 2017, 17:19

USAFged wrote:My problem is to make the mouse switch the .png files when I move the mouse cursor over them.
Try this ...

Code: Select all

#singleinstance force

Gui MyGui:New
Gui MyGui:Add, Picture, x100 y100 w100 h100, % "Red.png"
Gui MyGui:Add, Picture, x100 y300 w100 h100, % "Red.png"
Gui MyGui:Show, w500 h500, % "MyGui Title"

OnMessage(0x200, "WM_MOUSEMOVE")				; WM_MOUSEMOVE = 0x2A1

Esc::
ExitApp

WM_MOUSEMOVE(wParam, lParam, msg, hwnd) {
	static previousHoveredControl := ""
	MouseGetPos positionX, positionY, hoveredWindow, hoveredControl, 2					
	if(previousHoveredControl != hoveredControl) {										
		if(previousHoveredControl) {													
			GuiControlGet OriginalPictureName, , % previousHoveredControl
			GuiControl, , % previousHoveredControl, % OriginalPictureName
			previousHoveredControl := ""
		}
		if(hoveredControl) {															
			GuiControlGet OriginalPictureName, , % hoveredControl
			HoveredPictureName := StrReplace(OriginalPictureName, ".png", "2.png")
			GuiControl, , % hoveredControl, % HoveredPictureName
			previousHoveredControl := hoveredControl
		}
	}
}
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

16 Feb 2017, 20:15

Image

Forget to post an image of my GUI in my first post.
Thanks for replying to my post 4GForce.
I have not written any mouse commands at all in my script. Not sure how to adapt the code you wrote to my script.

Maybe I can explain what I need in a little different way.

As you can see in the image above the cursor is hovering over the Show Players text with the blue halo around it(ShowPlayers2.png) giving the impression that the Halo menu item Show Players as being selected.

All of the .png files are the same exact size(w380 h50).
All of the .png files with a 2 at the end of the file name has the blue halo around the off white text.
All of the .png files without a 2 at the end of the file name has the plain blue text.

The ShowPlayers2.png file is displayed at x20 y25 w380 h50. So if I move the mouse cursor < x20 or y25 or > x400 or y75 I need to hide the ShowPlayers2.png file so the ShowPlayers.png file under it will be displayed.

The next image file down Kick Player(KickPlayer.png) is 10 margin spaces down from ShowPlayers. ShowPlayers bottom edge is at y75 and KickPlayer top edge begins at y85. So if the cursor between y75 and y85 all of the .png file ending in 2 should be hidden displaying all image files with blue text.

If I move the mouse cursor down to the Kick Player text(KickPlayer.png) I need the image to change to Kick Player text with the blue halo around the text(KickPlayer2.png).

I hope this explains what I need better. Like I said I have never tried to script mouse commands before, so I need all the help I can get.

Thanks USAFged
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Switching .png files when mouse hovers over them

16 Feb 2017, 22:02

USAFged wrote:I hope this explains what I need better. Like I said I have never tried to script mouse commands before, so I need all the help I can get.
Just put your gui instead of mine and remove all the hidden controls, you wont need those.
Should work instantly, you don't need to add any code ( unless you want to filter out some controls )

Basically, every time the mouse moves it checks if there is a control under it, if so it changes the picture name by appending a 2

Code: Select all

Gui, 4:+Owner +AlwaysOnTop -Caption +Toolwindow +LastFound
Gui, 4:Color, F0F0F0
WinSet, TransColor, F0F0F0			
WinSet, Transparent, 225
WinSet, Region, 0-0 W420 H340 R45-45			
Gui, 4:Add, Picture, x0 y0 w420 h340, HaloHosting.png
Gui, 4:Add, Picture, x20 y25 BackgroundTrans gShowPlayers, ShowPlayers.png			
Gui, 4:Add, Picture, x20 y85 BackgroundTrans gKickPlayer, KickPlayer.png			
Gui, 4:Add, Picture, x20 y145 BackgroundTrans gBanPlayer, BanPlayer.png
Gui, 4:Add, Picture, x20 y205 BackgroundTrans gUnbanPlayer, UnbanPlayer.png		
Gui, 4:Add, Picture, x20 y265 BackgroundTrans gResetMap, ResetMap.png			
Gui, 4:Show, W420 H340
 	
OnMessage(0x200, "WM_MOUSEMOVE")				; WM_MOUSEMOVE = 0x2A1

Esc::
ExitApp

WM_MOUSEMOVE(wParam, lParam, msg, hwnd) {
	static previousHoveredControl := ""
	MouseGetPos positionX, positionY, hoveredWindow, hoveredControl, 2					
	if(previousHoveredControl != hoveredControl) {										
		if(previousHoveredControl) {													
			GuiControlGet OriginalPictureName, , % previousHoveredControl
			GuiControl, , % previousHoveredControl, % OriginalPictureName
			previousHoveredControl := ""
		}
		if(hoveredControl) {															
			GuiControlGet OriginalPictureName, , % hoveredControl
			HoveredPictureName := StrReplace(OriginalPictureName, ".png", "2.png")
			GuiControl, , % hoveredControl, % HoveredPictureName
			previousHoveredControl := hoveredControl
		}
	}
}
Edit: Not sure what's going to happen when you hover Halohosting.png ... might crash if there is no Halohosting2.png ... so we want to filter that one out

Code: Select all

	; ...

		if(hoveredControl) {															
			GuiControlGet OriginalPictureName, , % hoveredControl			
			if(OriginalPictureName != "HaloHosting.png") {									; Just exclude it here
				HoveredPictureName := StrReplace(OriginalPictureName, ".png", "2.png")
			        GuiControl, , % hoveredControl, % HoveredPictureName
				previousHoveredControl := hoveredControl
			}
		}
		
	; ...
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

17 Feb 2017, 19:18

It works exactly like I wanted it to except there is a lot flashing going on both on text .pngs and background also.

USAFged
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Switching .png files when mouse hovers over them

18 Feb 2017, 00:19

USAFged wrote:... except there is a lot flashing going on both on text .pngs and background also.
Hmmmm, Its not suppose to flash, unless you have overlapping controls ...
Could you post your code ?

Note that I don't have your pngs to test it but I'll take another look.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: Switching .png files when mouse hovers over them

18 Feb 2017, 00:53

You may want to use Class_ImageButton

Code: Select all

#Include Class_ImageButton.ahk ; https://autohotkey.com/boards/viewtopic.php?f=6&t=1103

DisableFadeEffect()

; Create background
Gui, Color, White
Gui, -Caption +LastFound
WinSet, TransColor, White

Gui, Add, Button, w420 h340 HWNDhBtn Disabled
opt1 := [0, 0x39495F,,, 25, "White", 0x409FFD, 5]
ImageButton.Create(hBtn, opt1, "", "", opt1)

; Create buttons
Gui, Font, s26 bold, Arial
Gui, Margin,, 10
CreateImgBtn("xp+25 yp+20 w370 h50", "SHOW PLAYERS")
CreateImgBtn("wp hp", "KICK PLAYER")
CreateImgBtn("wp hp", "BAN PLAYER")
CreateImgBtn("wp hp", "UNBAN PLAYER")
CreateImgBtn("wp hp", "RESET MAP")

Gui, Show
Return

GuiClose:
ExitApp

CreateImgBtn(Options, Text) {
	global
	static opt1 := [0, 0x39495F, "", 0x40A0FE]
	static opt2 := [0, 0x253245, "", 0xD1D1D1, 22, 0x38485E, 0x40A0FE, 5]

	Gui, Add, Button, %Options% HWNDhBtn, %Text%
	ImageButton.Create(hBtn, opt1, opt2)
}

DisableFadeEffect() {
	; SPI_GETCLIENTAREAANIMATION = 0x1042
	DllCall("SystemParametersInfo", "UInt", 0x1042, "UInt", 0, "UInt*", isEnabled, "UInt", 0)

	if isEnabled {
		; SPI_SETCLIENTAREAANIMATION = 0x1043
		DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 0, "UInt", 0)
		Progress, 10:P100 Hide
		Progress, 10:Off
		DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 1, "UInt", 0)
	}
}
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

18 Feb 2017, 14:01

4GForce wrote:Hmmmm, Its not suppose to flash, unless you have overlapping controls ...
Could you post your code ?
Here is the code I am using for the test script.

Code: Select all

Gui, 4:+Owner +AlwaysOnTop -Caption +Toolwindow +LastFound
Gui, 4:Color, F0F0F0
WinSet, TransColor, F0F0F0			
WinSet, Transparent, 225
WinSet, Region, 0-0 R45-45			
Gui, 4:Add, Picture, x0 y0 w420 h340, HaloHosting.png
Gui, 4:Add, Picture, x20 y25 BackgroundTrans gShowPlayers, ShowPlayers.png			
Gui, 4:Add, Picture, x20 y85 BackgroundTrans gKickPlayer, KickPlayer.png			
Gui, 4:Add, Picture, x20 y145 BackgroundTrans gBanPlayer, BanPlayer.png
Gui, 4:Add, Picture, x20 y205 BackgroundTrans gUnbanPlayer, UnbanPlayer.png		
Gui, 4:Add, Picture, x20 y265 BackgroundTrans gResetMap, ResetMap.png			
Gui, 4:Show, W420 H340
 	
OnMessage(0x200, "WM_MOUSEMOVE")				; WM_MOUSEMOVE = 0x2A1

Esc::
ExitApp

WM_MOUSEMOVE(wParam, lParam, msg, hwnd) 
{
	static previousHoveredControl := ""
	MouseGetPos positionX, positionY, hoveredWindow, hoveredControl, 2					
	if(previousHoveredControl != hoveredControl) 
	{										
		if(previousHoveredControl) 
		{													
			GuiControlGet OriginalPictureName, , % previousHoveredControl
			GuiControl, , % previousHoveredControl, % OriginalPictureName
			previousHoveredControl := ""
		}
		if(hoveredControl) 
		{															
			GuiControlGet OriginalPictureName, , % hoveredControl
			HoveredPictureName := StrReplace(OriginalPictureName, ".png", "2.png")
			GuiControl, , % hoveredControl, % HoveredPictureName
			previousHoveredControl := hoveredControl
		}
	}
	if(hoveredControl) 
	{															
		GuiControlGet OriginalPictureName, , % hoveredControl			
		if(OriginalPictureName != "HaloHosting.png") 
		{									; Just exclude it here
			HoveredPictureName := StrReplace(OriginalPictureName, ".png", "2.png")
			GuiControl, , % hoveredControl, % HoveredPictureName
			previousHoveredControl := hoveredControl
		}
	}
}

	ShowPlayers:
	MsgBox, You clicked on Show Players
	return
	
	KickPlayer:
	return
	
	BanPlayer:
	return
	
	UnbanPlayer:
	return
	
	ResetMap:
	return
tmplinshi wrote:You may want to use Class_ImageButton
I took your advice and the gui works good in halo except for 2 problems.
1. Where do I put my gLabels now. Example: gShowPlayers which shows the players currently playing on our server.
2. The cursor is changing images correctly but the selection goes to the plain blue text images below the one the cursor displays. I know this because if I leave the cursor over Shower Players the correct image displays. But if I push the up or down keys on the keyboard the selection moves up or down the plain blue text images. Instead it needs to display the same images the cursor displays.

Here is the code I am using in my halo script. I have commented out the old Gui except for what is needed.

Code: Select all

~`::
If vConsoleFlag = 0
{
	If vHaloExecution = Window
	{
		IfWinActive TeamSpeak 2
		{
			vConsoleFlag = 0
			Return
		}
		IfWinActive TeamSpeak 3
		{
			vConsoleFlag = 0
			Return
		}		
		IfWinActive Chat Buttons
		{
			vConsoleFlag = 0
			Return
		}
		IfWinActive Chat Setup
		{
			vConsoleFlag = 0
			Return
		}
		If vMultiPlayer = Joining
		{
			If vUseDirectIP = Yes
			{
				Sleep 500
				Gui, 4:+Owner +AlwaysOnTop -Caption +Toolwindow +LastFound
				Gui, 4:Color, F0F0F0
				WinSet, TransColor, F0F0F0
				WinSet, Transparent, 240
				WinSet, Region, 0-0 W820 H400 R45-45				
;				Gui, 4:Margin, 0, 0
				Gui, 4:Add, Picture, x0 y0 w820 h400, HaloJoining.png
				Gui, 4:Add, Picture, x20 y25 BackgroundTrans gShowPlayers, ShowPlayers.png
				Gui, 4:Add, Picture, x20 y85 BackgroundTrans gKickPlayer, KickPlayer.png
				Gui, 4:Add, Picture, x20 y145 BackgroundTrans gBanPlayer, BanPlayer.png
				Gui, 4:Add, Picture, x20 y205 BackgroundTrans gUnbanPlayer, UnbanPlayer.png
				Gui, 4:Add, Picture, x20 y265 BackgroundTrans gBanList, BanList.png
				Gui, 4:Add, Picture, x20 y325 BackgroundTrans gResetMap, ResetMap.png				
;				Gui, 4:Font, cMaroon s10 w700
;				Gui, 4:Add, GroupBox, xm+115 ym+5 Section w110 h205, Map Control
;				Gui, 4:Font, s9 w300
				Gui, 4:Add, Picture, x410 y25 BackgroundTrans gStartMapcycle, StartMapcycle.png
				Gui, 4:Add, Picture, x410 y85 BackgroundTrans gCurrentMaps, CurrentMaps.png
				Gui, 4:Add, Picture, x410 y145 BackgroundTrans gAddMap, AddMap.png
				Gui, 4:Add, Picture, x410 y205 BackgroundTrans gDeleteMap, DeleteMap.png
				Gui, 4:Add, Picture, x410 y265 BackgroundTrans gNextMap, NextMap.png
				Gui, 4:Add, Picture, x410 y325 BackgroundTrans gChooseMap, ChooseMap.png
				Gui, 4:Show, W820 H400
;				WinSet, Transparent, 230, Joining Console Buttons

				vConsoleFlag = 1
				return
			}
			Else If vUseDirectIP = No
			{
				return
			}
		}
		Else If vMultiPlayer = Hosting
		{
			#Include Class_ImageButton.ahk ; https://autohotkey.com/boards/viewtopic.php?f=6&t=1103

			DisableFadeEffect()

			; Create background
			Gui, 4:Color, White
			Gui, 4:-Caption +LastFound +Owner +AlwaysOnTop
			WinSet, TransColor, White
			WinSet, Transparent, 225
			WinSet, Region, 0-0 W420 H340 R45-45

			Gui, 4:Add, Button, x0 y0 w420 h340 HWNDhBtn Disabled
			opt1 := [0, 0x39495F,,, 25, "White", 0x409FFD, 5]
			ImageButton.Create(hBtn, opt1, "", "", opt1)

			; Create buttons
			Gui, 4:Font, s26 bold, Arial
			Gui, 4:Margin, x0 y0,
			CreateImgBtn("xp+20 yp+25 w380 h50", "SHOW PLAYERS")
			CreateImgBtn("wp hp", "KICK PLAYER")
			CreateImgBtn("wp hp", "BAN PLAYER")
			CreateImgBtn("wp hp", "UNBAN PLAYER")
			CreateImgBtn("wp hp", "RESET MAP")

			Gui, 4:Show
;			Return

;GuiClose:
;ExitApp

			CreateImgBtn(Options, Text) {
			global
			static opt1 := [0, 0x39495F, "", 0x40A0FE]
			static opt2 := [0, 0x253245, "", 0xD1D1D1, 22, 0x38485E, 0x40A0FE, 5]

			Gui, 4:Add, Button, %Options% HWNDhBtn, %Text%
			ImageButton.Create(hBtn, opt1, opt2)
		}
	
			DisableFadeEffect() {
			; SPI_GETCLIENTAREAANIMATION = 0x1042
			DllCall("SystemParametersInfo", "UInt", 0x1042, "UInt", 0, "UInt*", isEnabled, "UInt", 0)

			if isEnabled {
				; SPI_SETCLIENTAREAANIMATION = 0x1043
				DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 0, "UInt", 0)
				Progress, 10:P100 Hide
				Progress, 10:Off
				DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 1, "UInt", 0)
			}
		}
;			Gui, 4:+Owner +AlwaysOnTop -Caption +Toolwindow +LastFound
;			Gui, 4:Color, F0F0F0
;			WinSet, TransColor, F0F0F0			
;			WinSet, Transparent, 225
;			WinSet, Region, 0-0 W420 H340 R45-45			
;			Gui, 4:Add, Picture, x0 y0 w420 h340, HaloHosting.png
;			Gui, 4:Add, Picture, x20 y25 BackgroundTrans gShowPlayers, ShowPlayers.png			
;			Gui, 4:Add, Picture, x20 y25 Hidden BackgroundTrans gShowPlayers, ShowPlayers2.png
;			Gui, 4:Add, Picture, x20 y85 BackgroundTrans gKickPlayer, KickPlayer.png
;			Gui, 4:Add, Picture, x20 y85 Hidden BackgroundTrans gKickPlayer, KickPlayer2.png			
;			Gui, 4:Add, Picture, x20 y145 BackgroundTrans gBanPlayer, BanPlayer.png
;			Gui, 4:Add, Picture, x20 y145 Hidden BackgroundTrans gBanPlayer, BanPlayer2.png
;			Gui, 4:Add, Picture, x20 y205 BackgroundTrans gUnbanPlayer, UnbanPlayer.png
;			Gui, 4:Add, Picture, x20 y205 Hidden BackgroundTrans gUnbanPlayer, UnbanPlayer2.png			
;			Gui, 4:Add, Picture, x20 y265 BackgroundTrans gResetMap, ResetMap.png
;  			Gui, 4:Add, Picture, x20 y265 Hidden BackgroundTrans gResetMap, ResetMap2.png			
;			Gui, 4:Show, W420 H340
			MouseMove, 210, 50
		
			vConsoleFlag = 1
		}
	}
	Else If HaloExecution = Full Screen
	{
		vConsoleFlag = 0
	}
}
Else If vConsoleFlag = 1
{
	vConsoleFlag = 0
	Sleep 100
	Gui, 4:Destroy
	WinActivate Halo
	SendEvent {Enter}
}
Return
Thanks USAFged
Last edited by USAFged on 20 Feb 2017, 19:18, edited 1 time in total.
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

20 Feb 2017, 11:35

Code: Select all

		Else If vMultiPlayer = Hosting
		{
			#Include Class_ImageButton.ahk ; https://autohotkey.com/boards/viewtopic.php?f=6&t=1103

			DisableFadeEffect()

			; Create background
			Gui, 4:Color, White
			Gui, 4:-Caption +LastFound +Owner +AlwaysOnTop
			WinSet, TransColor, White
			WinSet, Transparent, 225
			WinSet, Region, 0-0 W420 H340 R45-45

			Gui, 4:Add, Button, x0 y0 w420 h340 HWNDhBtn Disabled
			opt1 := [0, 0x39495F,,, 25, "White", 0x409FFD, 5]
			ImageButton.Create(hBtn, opt1, "", "", opt1)

			; Create buttons
			Gui, 4:Font, s26 bold, Arial
			Gui, 4:Margin, x0 y0,
			CreateImgBtn("xp+20 yp+25 w380 h50", "SHOW PLAYERS")
			CreateImgBtn("wp hp", "KICK PLAYER")
			CreateImgBtn("wp hp", "BAN PLAYER")
			CreateImgBtn("wp hp", "UNBAN PLAYER")
			CreateImgBtn("wp hp", "RESET MAP")

			Gui, 4:Show
;			Return

;GuiClose:
;ExitApp

			CreateImgBtn(Options, Text) {
			global
			static opt1 := [0, 0x39495F, "", 0x40A0FE]
			static opt2 := [0, 0x253245, "", 0xD1D1D1, 22, 0x38485E, 0x40A0FE, 5]

			Gui, 4:Add, Button, %Options% HWNDhBtn, %Text%
			ImageButton.Create(hBtn, opt1, opt2)
		}
	
			DisableFadeEffect() {
			; SPI_GETCLIENTAREAANIMATION = 0x1042
			DllCall("SystemParametersInfo", "UInt", 0x1042, "UInt", 0, "UInt*", isEnabled, "UInt", 0)

			if isEnabled {
				; SPI_SETCLIENTAREAANIMATION = 0x1043
				DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 0, "UInt", 0)
				Progress, 10:P100 Hide
				Progress, 10:Off
				DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 1, "UInt", 0)
			}
		}
This is the part of my script that tmplinshi suggested I try and the display works like I wanted it to. Can someone tell me how to activate my g-labels and where to put them in the script.

Thanks USAFged
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Switching .png files when mouse hovers over them

20 Feb 2017, 16:11

USAFged wrote:Can someone tell me how to activate my g-labels and where to put them in the script.
If you really want labels you can just pass them in the options of CreateImgBtn, or use what I added to use functions

Code: Select all

CreateImgBtn("wp hp gKickPlayerLabel", "KICK PLAYER", "btnKickPlayerClicked")

CreateImgBtn(Options, Text, functionName := "") {
	global
	static opt1 := [0, 0x39495F, "", 0x40A0FE]
	static opt2 := [0, 0x253245, "", 0xD1D1D1, 22, 0x38485E, 0x40A0FE, 5]

	Gui, 4:Add, Button, %Options% HWNDhBtn, %Text%
	if(functionName) {
		fn := Func(functionName)
		GuiControl, +g, %fn%, %hBtn%
	}
	ImageButton.Create(hBtn, opt1, opt2)
	Return hBtn
}

KickPlayerLabel:
	msgbox % "Kick him label !"
Return

btnKickPlayerClicked() {
	msgbox % "Kick him function !"
}
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

20 Feb 2017, 19:39

4GForce wrote:If you really want labels you can just pass them in the options of CreateImgBtn, or use what I added to use functions
Thank you so much for your help 4GForce.
I decided to keep the labels because this is the smallest of 3 Guis I want to display like this and they all use labels which are already working the way I want them to.

Would you happen to know how I can make the image that the cursor displays, with the halo encircled text, display over the other text items when I press the up or down keys giving the impression the cursor keys are selecting the text like the mouse does. They select the plain blue text instead.

Thanks again
USAFged
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: Switching .png files when mouse hovers over them

20 Feb 2017, 22:24

USAFged wrote:
4GForce wrote:Would you happen to know how I can make the image that the cursor displays, with the halo encircled text, display over the other text items when I press the up or down keys giving the impression the cursor keys are selecting the text like the mouse does. They select the plain blue text instead.
Have you tried creating the button without text ? ( as far as I understood the text is in the image ? )
CreateImgBtn("wp hp gKickPlayerLabel", "")

If that doesn't help maybe a ctrl+a ... send ^{a} ... to simulate a select all ...

Or for further control over cursors you might need to DllCall a method of Cursors
https://msdn.microsoft.com/en-us/librar ... 46970.aspx
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

05 Mar 2017, 15:44

4GForce wrote:Have you tried creating the button without text ? ( as far as I understood the text is in the image ? )
CreateImgBtn("wp hp gKickPlayerLabel", "")
Doing it like that only creates a blank button which you can still select and when pressing still activated the gKickPlayer label. I need the g-labels to only work when the halo encircled text is selected with the mouse or up and down arrow buttons. I am wanting my gui to perform and look as close as possible as the Halo Combat Evolved game menus.
4GForce wrote:If that doesn't help maybe a ctrl+a ... send ^{a} ... to simulate a select all ...
I see no difference in the way it acts.

Could making a image with the light blue text already on it and only create the buttons text with the halo encircled text for the selection work?
bigdeal
Posts: 66
Joined: 13 Feb 2017, 06:31

Re: Switching .png files when mouse hovers over them

06 Mar 2017, 02:17

4GForce wrote:

Code: Select all

btnKickPlayerClicked() {
	msgbox % "Kick him function !"
}
hi this is bugging me: what does that label do exactly?
I also have to say this thread is very helpful and interesting =)
bigdeal
Posts: 66
Joined: 13 Feb 2017, 06:31

Re: Switching .png files when mouse hovers over them

06 Mar 2017, 04:03

eh whatever i don't know why but I expected more from that class_imagebutton, but maybe that's cus Im a newbie i dunno
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

06 Mar 2017, 08:50

bigdeal wrote:hi this is bugging me: what does that label do exactly?
I also have to say this thread is very helpful and interesting =)
When playing Halo Combat Evolved there is a command prompt you can bring up to enter commands to kick, ban, unban, etc,. players currently playing on your server. It is the caret key above the tab key. In my script when it is pressed the command prompt pops up and so does my gui with my command buttons when playing Halo in full display Window mode. If I need to kick a player from the server, all I need to do is click on the Kick Player button and the gKickPlayer label executes the following code.

Code: Select all

KickPlayer:
Gui 4:Destroy
WinActivate Halo
Sleep 200
If vMultiplayer = Joining
{
	SendEvent, rcon{SPACE}%vRconPassword%{SPACE}sv{SHIFTDOWN}-{SHIFTUP}players
	Sleep 500
	SendEvent, {Enter}
	Sleep 500
	SendEvent, rcon{SPACE}%vRconPassword%{SPACE}sv{SHIFTDOWN}-{SHIFTUP}kick{Space}
}
Else If vMultiplayer = Hosting
{
	SendEvent, sv{SHIFTDOWN}-{SHIFTUP}players
	Sleep 500
	SendEvent, {Enter}
	Sleep 500
	SendEvent, sv{SHIFTDOWN}-{SHIFTUP}kick{Space}
}
KeyWait, Enter, d
Sleep 500
SendEvent {Enter}
vConsoleFlag = 0
Return
If I decide to play Halo in full screen mode and I press the caret key, the command prompt will pop up without the gui and I will need to press the hotkeys to kick the player. The following code is then executed.

Code: Select all

!k::
If vMultiplayer = Joining
{
	Sleep 500
	SendEvent, rcon{SPACE}%vRconPassword%{SPACE}sv{SHIFTDOWN}-{SHIFTUP}players
	Sleep 500
	SendEvent, {Enter}
	Sleep 500
	SendEvent, rcon{SPACE}%vRconPassword%{SPACE}sv{SHIFTDOWN}-{SHIFTUP}kick{Space}
	KeyWait, Enter, d
	Sleep 500
	SendEvent {Enter}
}
Else If vMultiplayer = Hosting
{
	Sleep 500
	SendEvent, sv{SHIFTDOWN}-{SHIFTUP}players
	Sleep 500
	SendEvent, {Enter}
	Sleep 500
	SendEvent, sv{SHIFTDOWN}-{SHIFTUP}kick{Space}
	KeyWait, Enter, d
	Sleep 500
	SendEvent {Enter}
}
Return
As you can see by looking at the code it depends on if you are playing on a dedicated server (Joining) or (Hosting) your own game online.
bigdeal wrote:eh whatever i don't know why but I expected more from that class_imagebutton, but maybe that's cus Im a newbie i dunno
The class_imagebutton is working great with the mouse cursor. I just need to get it to act the same way when using the up or down arrow keys. For instance my gui defaults to the image displayed a few posts above because the script is telling the mouse cursor to move over the center of the Show Players text showing it is under the mouse cursor. If I push the down arrow I need the Show Players text to change to the lite blue text and the Kick Player in lite blue text to change to white encircled in the lite blue halo to show it has been selected like in the image below.

Image

Then all I have to do is press the enter key to activate the Kick Player g-label.

As of now this is what I am getting when I press the down arrow key.

Image

The Kick Player g-label executes correctly when I press the enter key, but the selection display does not change.

USAFged
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

09 Mar 2017, 21:38

I figured out a way to use the arrow keys. Pretty sure it is not the best way to do it. But when I press the enter key it will not excute the g-labels like the mouse does.

Code: Select all

#Include Class_ImageButton.ahk ; https://autohotkey.com/boards/viewtopic.php?f=6&t=1103

DisableFadeEffect()

; Create background
Gui, Color, White
Gui, -Caption +LastFound
WinSet, TransColor, White

Gui, Add, Button, w420	h340 HWNDhBtn Disabled
opt1 := [1, 0x39495F,,, 25, "White", 0x409FFD, 5]
ImageButton.Create(hBtn, opt1, "", "", opt1)
OnMessage(0x200, "WM_MOUSEMOVE")

; Create buttons
Gui, Font, s26 bold, Arial
Gui, Margin,, 10

CreateImgBtn("xp+20 yp+25 w380 h50 vShowPlayers gShowPlayers", "SHOW PLAYERS")
CreateImgBtn("wp hp vKickPlayer gKickPlayer", "KICK PLAYER")
CreateImgBtn("wp hp vBanPlayer gBanPlayer", "BAN PLAYER")
CreateImgBtn("wp hp vUnbanPlayer gUnbanPlayer", "UNBAN PLAYER")
CreateImgBtn("wp hp vResetMap gResetMap", "RESET MAP")
;CreateImgBtn("x420 y30 wp hp", "START MAPCYCLE")
;CreateImgBtn("wp hp", "ADD MAP") 
;CreateImgBtn("wp hp", "DELETE MAP")
;CreateImgBtn("wp hp", "NEXT MAP")
;CreateImgBtn("wp hp", "CHOOSE MAP")
vShowPlayers = 0
vKickPlayer = 0
vBanPlayer = 0
vUnbanPlayer = 0
vResetMap = 0
Gui, Show
MouseMove, 210, 50

Return

Down::
If var, vShowPlayers
	vShowPlayers = 0
	MouseMove, 210, 110
	vKickPlayer = 1
	KeyWait, Down, D
If var, vKickPlayer
	vKickPlayer = 0	
	MouseMove, 210, 170
	vBanPlayer = 1
	KeyWait, Down, D
If var, vBanPlayer
	vBanPlayer = 0
	MouseMove, 210, 230
	vUnbanPlayer = 1
	KeyWait, Down, D
If var, vUnbanPlayer
	vUnbanPlayer = 0
	MouseMove, 210, 290
	vResetMap = 1
	KeyWait, Down, D
If var vResetMap
	vResetMap = 0
	MouseMove, 210, 50
	vShowPlayers = 1
	KeyWait, Down, D
return

Up::
If var, vShowPlayers
	vShowPlayers = 0
	MouseMove, 210, 290
	vResetMap = 1
	KeyWait, Up, D
If var, vResetMap
	vResetMap = 0
	MouseMove, 210, 230
	vUnbanPlayer = 1
	KeyWait, Up, D
If var, vUnbanPlayer
	vUnbanPlayer = 0
	MouseMove, 210, 170
	vBanPlayer = 1
	KeyWait, Up, D
If var, vBanPlayer
	vBanPlayer = 0
	MouseMove, 210, 110
	vKickPlayer = 1
	KeyWait, Up, D
If var, vKickPlayer
	vKickPlayer = 0
	MouseMove, 210, 50
	vShowPlayers = 1
	KeyWait, Up, D	
return

ShowPlayers:
MsgBox, 4, Show Players Test, You clicked on Show Players
return
	
KickPlayer:
MsgBox, 4, Kick Player Test, You clicked on Kick Player
return
	
BanPlayer:
MsgBox, 4, Ban Player Test, You clicked on Ban Player
return
	
UnbanPlayer:
MsgBox, 4, Unban Player Test, You clicked on Unban Player
return

ResetMap:
MsgBox, 4, Reset Map Test, You clicked on Reset Map
return

GuiClose:
Esc::
ExitApp

CreateImgBtn(Options, Text) {
	global
	static opt1 := [0, 0x39495F, "", 0x40A0FE]
	static opt2 := [0, 0x253245, "", 0xD1D1D1, 22, 0x38485E, 0x40A0FE, 5]

	Gui, Add, Button, %Options% HWNDhBtn, %Text%
	ImageButton.Create(hBtn, opt1, opt2)
}

DisableFadeEffect() {
	; SPI_GETCLIENTAREAANIMATION = 0x1042
	DllCall("SystemParametersInfo", "UInt", 0x1042, "UInt", 0, "UInt*", isEnabled, "UInt", 0)

	if isEnabled {
		; SPI_SETCLIENTAREAANIMATION = 0x1043
		DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 0, "UInt", 0)
		Progress, 10:P100 Hide
		Progress, 10:Off
		DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 1, "UInt", 0)
;		SoundGet
	}
}
Sure could use some help on this!!

USAFged
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

14 Mar 2017, 17:49

I have tried everything I know with my limited knowledge of AutoHotKeys. The mouse part of the script works exactly the way I need it to. All I need is the text to switch the images like the mouse does when the arrow keys selected them. Here is the bare bones code anyone can copy and run to see what I am talking about.

Code: Select all

#Include Class_ImageButton.ahk ; https://autohotkey.com/boards/viewtopic.php?f=6&t=1103
	vShowPlayers = 0
	vKickPlayer = 0
	vBanPlayer = 0
	vUnbanPlayer = 0
	vResetMap = 0
DisableFadeEffect()

; Create background
Gui, 4:Color, White
Gui, 4:-Caption +LastFound
WinSet, TransColor, White

Gui, 4:Add, Button, w420	h340 HWNDhBtn Disabled
opt1 := [1, 0x39495F,,, 25, "White", 0x409FFD, 5]
ImageButton.Create(hBtn, opt1, "", "", opt1)
OnMessage(0x200, "WM_MOUSEMOVE")

; Create buttons
Gui, 4:Font, s26 bold, Arial
Gui, 4:Margin,, 10

CreateImgBtn("xp+20 yp+25 w380 h50 vShowPlayers gShowPlayers", "SHOW PLAYERS")
CreateImgBtn("wp hp vKickPlayer gKickPlayer", "KICK PLAYER")
CreateImgBtn("wp hp vBanPlayer gBanPlayer", "BAN PLAYER")
CreateImgBtn("wp hp vUnbanPlayer gUnbanPlayer", "UNBAN PLAYER")
CreateImgBtn("wp hp vResetMap gResetMap", "RESET MAP")

Gui, 4:Show
MouseMove, 210, 50
vShowPlayers = 1
vConsoleFlag = 1
CreateImgBtn(Options, Text)
{
	global
	static opt1 := [0, 0x39495F, "", 0x40A0FE]
	static opt2 := [0, 0x253245, "", 0xD1D1D1, 22, 0x38485E, 0x40A0FE, 5]
	
	Gui, 4:Add, Button, %Options% HWNDhBtn, %Text%
	ImageButton.Create(hBtn, opt1, opt2)
}

DisableFadeEffect()
{
	; SPI_GETCLIENTAREAANIMATION = 0x1042
	DllCall("SystemParametersInfo", "UInt", 0x1042, "UInt", 0, "UInt*", isEnabled, "UInt", 0)

	if isEnabled
	{
		; SPI_SETCLIENTAREAANIMATION = 0x1043
		DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 0, "UInt", 0)
		Progress, 10:P100 Hide
		Progress, 10:Off
		DllCall("SystemParametersInfo", "UInt", 0x1043, "UInt", 0, "UInt", 1, "UInt", 0)
	}
}
return

;Hosting Button Labels
ShowPlayers:
;Gui 4:Destroy
MsgBox,, Show Players Test, You clicked on Show Players
vConsoleFlag = 0
return
	
KickPlayer:
;Gui 4:Destroy
MsgBox, 4, Kick Player Test, You clicked on Kick Player
vConsoleFlag = 0
return

BanPlayer:
;Gui 4:Destroy
MsgBox, 4, Ban Player Test, You clicked on Ban Player
vConsoleFlag = 0
return
	
UnbanPlayer:
;Gui 4:Destroy
MsgBox, 4, Unban Player Test, You clicked on Unban Player
vConsoleFlag = 0
return

ResetMap:
;Gui 4:Destroy
MsgBox, 4, Reset Map Test, You clicked on Reset Map
vConsoleFlag = 0`
return

;Closing Application
GuiClose:
Esc::
ExitApp
All you need is the Class_ImageButton.ahk to run it.

Please help if you know a way of doing this.

Thanks USAFged
USAFged
Posts: 11
Joined: 29 Jan 2017, 20:54

Re: Switching .png files when mouse hovers over them

02 May 2017, 15:39

If this cannot be done can someone please tell me.

Thanks
USAFged

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Hansielein, Lpanatt and 317 guests