Unreliable results changing GUI color on keypress. Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Unreliable results changing GUI color on keypress.

Post by Off Topic » 07 Nov 2017, 00:31

As seen here:

Image

The three rectangles at the bottom are individual GUIs that the Edit boxes submit hex values to and those update color reliably, exactly what I want for storing certain temporary colors, and the ones near my cursor are for modifier visualization, so when I'm holding down control, shift, or alt. When I connect the variable color to the modifier keys, they tend to flash the original color every 3rd or so keypress (but it seems random) and I'm not sure how to fix this. This is what I'm going for:

Image

Right now I can't get more than one modifier key to light up at the same time, and I don't know how to address the image overlay above that. I figure that I would need to use GetKeyState to display a different image depending on which modifier keys are being held, but I don't really know how to approach building it from a conditional statement or where to put it/how to trigger it--which is why I used KeyWait to change colors in the working sample at the top. Parts of the script:

Code: Select all

Gosub, NumberGUI
Gosub, SideGUI
Gosub, SideAStrip
Gosub, TitleGUI
return   

SideGUI:
	Gui LSide:new
	Gui, Margin , 0, 0
	Gui, +AlwaysOnTop -Border -SysMenu +Owner -Caption +ToolWindow hwndLSide
	Gui, font, c111111 s8, Verdana
	Gui, Add, Button, x-25 y-10 Hidden gButtonA, R
	Gui, Add, Button, x-25 y-10 Hidden gButtonA, G
	Gui, Add, Button, x-25 y-10 Hidden gButtonA, B
	Gui, Add, Picture, xm+384 ym+651, MyTLSide.png
	Gui, Add, Edit, Limit6 x%1xA% y%E1y% w50 h17 -VScroll BackgroundTrans vRstripColor +WantReturn hwndR, d44400
	Gui, Add, Edit, Limit6 x%1xA% y%E2y% w50 h17 -VScroll BackgroundTrans vGstripColor +WantReturn hwndG, 24ee49
	Gui, Add, Edit, Limit6 x%1xA% y%E3y% w50 h17 -VScroll BackgroundTrans vBstripColor +WantReturn hwndB, 5064f1
	Gui, Color, %Mask%
	Gui +LastFound
	WinSet, TransColor, %Mask%
	Gui, Show, x0 y0
	return

SideAStrip:
	Gui LSide: Submit, NoHide
	Gui RStrip:new
	Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndRStrip
	Gui, Color, %RstripColor%
	Gui, Show, x%2x% y%Ry% w10 h17
	Gui GStrip:new
	Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndGStrip
	Gui, Color, %GstripColor%
	Gui, Show, x%2x% y%Gy% w10 h17
	Gui BStrip:new
	Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndBStrip
	Gui, Color, %BstripColor%
	Gui, Show, x%2x% y%By% w10 h17
	return

~LControl::
		Gui ModCtrl:new
		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndModCtrl
		Gui, Color, %RstripColor%
		Gui, Show, NoActivate x594 y1136 w20 h10
		KeyWait, LControl
		Gui ModCtrl:new
		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
		Gui, Color, 373737
		Gui, Show, NoActivate x594 y1136 w20 h10
		Return

~LShift::
		Gui ModShift:new
		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndModShift
		Gui, Color, %GstripColor%
		Gui, Show, NoActivate x594 y1114 w31 h10
		KeyWait, LShift
		Gui ModShift:new
		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
		Gui, Color, 373737
		Gui, Show, NoActivate x594 y1114 w31 h10
		Return

~LAlt::
		Gui AltShift:new
		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndAltShift
		Gui, Color, %BstripColor%
		Gui, Show, NoActivate x633 y1136 w19 h10
		KeyWait, LAlt
		Gui AltShift:new
		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
		Gui, Color, 373737
		Gui, Show, NoActivate x633 y1136 w19 h10
		Return

ButtonA:
	Gosub, SideAStrip
	Return
Can I get a point in the right direction or a barebones pseudocode example of how to fix the above so I can have multiple keys light up? Its a roadblock for me because all I need to do to finish is the same conditional show/hide for the mouse charts above it. I'm a very visual person and I have a hard time extrapolating the logic when not in the direct context I'm trying to use it for--I haven't had to use anything but basic one line If statements, and I don't know if I would have to trigger it within the hotkeys and only for the ones they effect, or outside of it using something like SetTimer or Loop, or where to even put it in my code. I'm new to coding and have stumbled my way this far.
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Re: Unreliable results changing GUI color on keypress.

Post by Off Topic » 07 Nov 2017, 09:55

Bump for visibility. I'm new to coding and could really use some help.
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.  Topic is solved

Post by just me » 07 Nov 2017, 11:27

:arrow: You can use the following modifier symbols to define hotkeys:
The * symbol might help.
BTW: If all parts of the picture shown in the OP are parts of your own GUIs, why do you think to need different GUIs?
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Re: Unreliable results changing GUI color on keypress.

Post by Off Topic » 07 Nov 2017, 13:19

Image Well that makes me feel really dumb lol. I plugged that in and it works, I was actually using wildcard in other hotkeys but I'd read a post claiming this was an implicit limitation of KeyWait so that's where I thought the problem was--thanks though! It fixed the color too but admittedly I'm not sure why it would since I was only doing single keypresses in the gif above.
just me wrote:BTW: If all parts of the picture shown in the OP are parts of your own GUIs, why do you think to need different GUIs?
What would you recommend? I'm really new to coding and I have a hard time extrapolating things if not in the direct context I need them, I couldn't find examples of GUIs or controls changing color to Edit boxes like the above. I had compatibility problems trying to write them all in the same script too, I have 9 total hidden within the UI of Adobe Illustrator, and I found that it was much easier to debug them if I wrote new ones in a new script and ran that independently to make sure things work and to have a better idea of where the conflicts were.

Would you be able to point me in the right direction or help me get started on the conditional image overlay above the keys? I don't understand where I'd put that in a script, and the only way I can think to do it is to have a long single conditional expression using GetKeyState with all the explicit Down/Up states that each contain a rebuild of the intended GUI every time--so I fear I'm overcomplicating since that's the source of most of my AHK problems so far--I haven't had to do anything but really simple If/Else statements yet so it's intimidating to the point of being reluctant to try (I don't know how many hours I'd spin my wheels doing things wrong rather than get someone with experience to give me some barebones pseudocode or advice), I'd really appreciate it.
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.

Post by just me » 08 Nov 2017, 05:43

To help you, we need more detailed information about what you want to achieve. Your animations seem to show various changes of parts of the GUIs. You should show your actual code and give a a verbal description about what every part of your GUIs should contain and under which condition it should be shown, hidden or changed.
I have 9 total hidden within the UI of Adobe Illustrator
The problem with this is, that your animation won't show hidden GUIs and the related code. So nobody can get an idea what they are intended to do.
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Re: Unreliable results changing GUI color on keypress.

Post by Off Topic » 09 Nov 2017, 02:29

just me wrote:To help you, we need more detailed information about what you want to achieve. Your animations seem to show various changes of parts of the GUIs. You should show your actual code and give a a verbal description about what every part of your GUIs should contain and under which condition it should be shown, hidden or changed.

The problem with this is, that your animation won't show hidden GUIs and the related code. So nobody can get an idea what they are intended to do.
Sorry about that. By "hidden" I mean that I'd like to disguise them as native Adobe Illustrator panels as best I can because it's distracting when they're sore thumbs, I have it working in a new script now except for recreating the color updates of the bottom Edit boxes for hex values and their color tags:


Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Mask = ffffff
Rc = d44400 
Gc = 24ee49
Bc = 5064f1

#SingleInstance, Force

Gosub, ModGUIsub
Gosub, MouseGUIsub
Gosub, EditGUIsub
return

; This is the GUI that lights up modifier keys as I hold them
ModGUIsub:		
		Gui, Margin
		Gui ModGUI:new
		Gui +AlwaysOnTop +Border -SysMenu -Owner -Caption +ToolWindow hwndModGUI
		Gui, Add, Progress, yp w31 h10 c%Rc% background0x%Mask% vMyShift, 0
		Gui, Add, Progress, yp+14 w20 h10 c%Gc% background0x%Mask% vMyCtrl, 0
		Gui, Add, Progress, xp+26 yp w19 h10 c%Bc% background0x%Mask% vMyAlt, 0
		Gui, Color, %Mask%
		Gui +LastFound
		WinSet, TransColor, %Mask%
		Gui, Show, x579 y1114
		return

; GUI to display different mouse layout/chart depending on what modifier keys are held
MouseGUIsub:
        Gui, MouseGUI:Destroy
        Gui MouseGUI:new
        Gui, Color, 373737
        Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndMouseGUI
        Gui, Add, Picture, vMyPic, MyTmGui_def.png
        Gui +LastFound
        WinSet, TransColor, 373737
        Gui, Show, x559 y970
        SetTimer, KeyChecker, -1
        return

; Loop to update the MouseGUIsub charts
KeyChecker:
		Loop
		{
		    sleep, 125
		    AltState =
		    CtrlState =
		    ShiftState =
		    GetKeyState, AltState, LAlt, P
		    GetKeyState, CtrlState, LControl, P
		    GetKeyState, ShiftState, LShift, P
		    if ( (AltState = "D") && (CtrlState = "D") && (ShiftState = "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_keymap.png
		        continue
		    }
		     if ( (AltState = "D") && (CtrlState = "D") && (ShiftState != "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_^!.png
		        continue

		    }
		     if ( (AltState = "D") && (CtrlState != "D") && (ShiftState = "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_+!.png
		        continue
		    }
		     if ( (AltState != "D") && (CtrlState = "D") && (ShiftState = "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_^+.png
		        continue
		    }
			 if ( (AltState != "D") && (CtrlState = "D") && (ShiftState = "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_^+.png
		        continue
		    }
		     if ( (AltState != "D") && (CtrlState != "D") && (ShiftState = "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_+.png
		        continue
		    }
		     if ( (AltState != "D") && (CtrlState = "D") && (ShiftState != "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_^.png
		        continue
		    }
		     if ( (AltState = "D") && (CtrlState != "D") && (ShiftState != "D") )
		    {
		        GuiControl, MouseGUI:, MyPic, MyTmGui_!.png
		        continue
		    }
		    GuiControl, MouseGUI:, MyPic, MyTmGui_def.png
		}
		return


; Hotkeys to trigger the ModGUIsub
~*LControl::
        GuiControl, ModGUI:, MyCtrl, 100
        Return

~*LControl Up::
        GuiControl, ModGUI:, MyCtrl, 0
        Return

~*LShift::
        GuiControl, ModGUI:, MyShift, 100
        Return

~*LShift Up::
        GuiControl, ModGUI:, MyShift, 0
        Return

~*LAlt::
        GuiControl, ModGUI:, MyAlt, 100
        Return

~*LAlt Up::
        GuiControl, ModGUI:, MyAlt, 0
        Return

; 	This part isn't working as well as creating new GUIs like in my earlier script
EditGUIsub:
	Gui LSide:Destroy
	Gui LSide:new
	Gui, Color, 373737

	;	When I make the gui transparent for white text, I have too hard a time selecting/clicking the Edit boxes? 

	; Gui +LastFound
	; WinSet, TransColor, %Mask%
	Gui, Margin , 0, 0
	Gui, +AlwaysOnTop +Border -SysMenu +Owner -Caption +ToolWindow hwndLSide
	Gui, font, c111111 s9 q4, Arial
	
	;	I thought this would be a better option, but my progress control flashes white once I change the text, doesn't refresh color

	Gui, Add, Progress, w12 h20 cd44400 background0x1d1d1d vRshifter, 100
	Gui, Add, Edit, xp+15 yp Limit6 w50 h20 -Border -VScroll vRstripColor gButtonA +WantReturn hwndR, d44400
	Gui, Add, Edit, yp+26 Limit6 w50 h20 -Border -VScroll vGstripColor +WantReturn hwndG, 24ee49
	Gui, Add, Edit, yp+26 Limit6 w50 h20 -Border -VScroll vBstripColor +WantReturn hwndB, 5064f1
	Gui, Show, x575 y1270
	return

ButtonA:
		Gui, LSide:Submit, NoHide
		GuiControl, LSide:, RShifter, c%RstripColor%
		return

Esc::ExitApp
This works much better thanks to an example I was given though I can't imagine I've done everything right, my only trouble at the moment is recreating the updating color labels next to the Edits. How would I link progress controls to update to the edit boxes submitted value in the same gui without rebuilding? The way I'd done it previously was in having 4 separate guis and respawning them, I commented out the irrelevant parts but am including for clarity:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force

;				GlobalVar
	mainProg    := "illustrator"
	Mask = 373737

	; Y Positions
	Ry = 1274
	Gy = 1311
	By = 1349
	Ty = 790
	N1y = 813
	N2y = 830
	E1y = 849
	E2y = 874
	E3y = 899
	My = 700

	; X Positions
	1x  = 584
	1xA = 398
	2x  = 578
	Nx = 386
	Tx = 428
	Mx = 396

;Gosub, NumberGUI
Gosub, SideGUI
Gosub, SideAStrip
;Gosub, TitleGUI
return   

SideGUI:
	Gui LSide:Destroy
	Gui LSide:new
	Gui, Margin , 0, 0
	Gui, +AlwaysOnTop -Border -SysMenu +Owner -Caption +ToolWindow hwndLSide
	Gui, font, c111111 s8, Verdana
	Gui, Add, Button, x-25 y-10 Hidden gButtonA, R
	Gui, Add, Button, x-25 y-10 Hidden gButtonA, G
	Gui, Add, Button, x-25 y-10 Hidden gButtonA, B
	; Gui, Add, Picture, xm+384 ym+651, MyTLSide.png
	Gui, Add, Picture, xm+384 ym+732, MyTLSideDown.png
	Gui, Add, Edit, Limit6 x%1xA% y%E1y% w50 h17 -VScroll +BackgroundTrans vRstripColor +WantReturn hwndR, d44400
	Gui, Add, Edit, Limit6 x%1xA% y%E2y% w50 h17 -VScroll +BackgroundTrans vGstripColor +WantReturn hwndG, 24ee49
	Gui, Add, Edit, Limit6 x%1xA% y%E3y% w50 h17 -VScroll +BackgroundTrans vBstripColor +WantReturn hwndB, 5064f1
	Gui, Color, %Mask%
	Gui +LastFound
	WinSet, TransColor, %Mask%
	Gui, Show, x0 y0
	return

SideAStrip:
	Gui LSide: Submit, NoHide
	Gui RStrip:new
	Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndRStrip
	Gui, Color, %RstripColor%
	Gui, Show, x%2x% y%Ry% w10 h17
	Gui GStrip:new
	Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndGStrip
	Gui, Color, %GstripColor%
	Gui, Show, x%2x% y%Gy% w10 h17
	Gui BStrip:new
	Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndBStrip
	Gui, Color, %BstripColor%
	Gui, Show, x%2x% y%By% w10 h17
	return

ButtonA:
	Gosub, SideAStrip
	Return
	
; NumberGUI:
; 	Gui NSide:Destroy
; 	Gui NSide:new
; 	Gui, Margin , 0, 0
; 	Gui, +AlwaysOnTop -Border -SysMenu +Owner -Caption +ToolWindow hwndNSide
; 	Gui, font, c111111 s8, Verdana
; 	Gui, Add, Button, x-25 y%N1y% , N1
; 	Gui, Add, Button, x-25 y%N2y% , N2
; 	Gui, Add, Edit, Limit1 x%Nx% y%N1y% w30 h13 -VScroll BackgroundTrans vN1a +WantReturn HwndN1,
; 	Gui, Add, UpDown, vScrollBoxB , 2
; 	Gui, Add, Edit, Limit1 x%Nx% y%N2y% w30 h13 -VScroll BackgroundTrans vN2a +WantReturn HwndN2,
; 	Gui, Add, UpDown, vScrollBoxC , 5
; 	Gui, Color, %Mask%
; 	Gui +LastFound
; 	WinSet, TransColor, %Mask%
; 	Gui, Show, x0 y0
; 	return

; TitleGUI:
; 	Gui Title:Destroy
; 	Gui Title:new
; 	Gui, Margin , 0, 0
; 	Gui, +AlwaysOnTop -Border -SysMenu +Owner -Caption +ToolWindow hwndLSide
; 	Gui, font, c111111 s9, Verdana
; 	Gui, Add, Button, x%Nx% y%Ty% Hidden , Title
; 	Gui, Add, Edit, Limit2 x%Tx% y%Ty% w20 h17 -VScroll BackgroundTrans vvarTitle +WantReturn hwndMMTitle,38
; 	Gui, Color, %Mask%
; 	Gui +LastFound
; 	WinSet, TransColor, %Mask%
; 	Gui, Show, x0 y0
; 	Return

; ~*LControl::
; 		Gui ModCtrl:Destroy
; 		Gui ModCtrl:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndModCtrl
; 		Gui, Color, %RstripColor%
; 		Gui, Show, NoActivate x594 y1136 w20 h10
; 		KeyWait, LControl
; 		Gui ModCtrl:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
; 		Gui, Color, 373737
; 		Gui, Show, NoActivate x594 y1136 w20 h10
; 		Return

; ~*LShift::
; 		Gui Modshift:Destroy
; 		Gui ModShift:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndModShift
; 		Gui, Color, %GstripColor%
; 		Gui, Show, NoActivate x594 y1114 w31 h10
; 		KeyWait, LShift
; 		Gui ModShift:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
; 		Gui, Color, 373737
; 		Gui, Show, NoActivate x594 y1114 w31 h10
; 		Return

; ~*LAlt::
; 		Gui AltShift:Destroy
; 		Gui AltShift:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow hwndAltShift
; 		Gui, Color, %BstripColor%
; 		Gui, Show, NoActivate x633 y1136 w19 h10
; 		KeyWait, LAlt
; 		Gui AltShift:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
; 		Gui, Color, 373737
; 		Gui, Show, NoActivate x633 y1136 w19 h10
; 		Return

; ~*LButton::
; 		Gui LButton:Destroy
; 		Gui LButton:new
; 		Gui +AlwaysOnTop +Border -SysMenu -Owner -Caption +ToolWindow hwndA1LButton
; 		Gui, Color, ffffff
; 		Gui, Show, NoActivate x596 y998 w13 h17
; 		KeyWait, LButton
; 		Gui LButton:new
; 		Gui +AlwaysOnTop -Border -SysMenu -Owner -Caption +ToolWindow
; 		Gui, Color, 373737
; 		Gui, Show, NoActivate x596 y998 w0 h0
; 		Return


; Reset RGB
F21::
	BlockInput, MouseMove
	WinActivate, ahk_id %LSide%
		Click, 650, 1285 Left, Down
		Sleep, 20
		Click, 650, 1285 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Sleep, 20
	SendInput, d44400
	Sleep, 20
	Send, {Tab}
	Sleep, 20
	SendInput, 24ee49
	Sleep, 20
	Send, {Tab}
	Sleep, 20
	SendInput, 5064f1
	Sleep, 20
	Send, {Enter}
	Gosub, ButtonA
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return 

; DropR
F22::
	BlockInput, MouseMove
	Gui LSide: Submit, NoHide
		Clipboard := RstripColor
		ClipWait, 0,
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 229 Left, Down
		Sleep, 20
		Click, 2506, 239 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Send, %Clipboard%
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return
^F22::
	BlockInput, MouseMove
	Clipboard = 
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 230 Left, Down
		Sleep, 20
		Click, 2506, 230 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{c}{CtrlUp}
	ClipWait, 1
	Sleep, 50
	WinActivate, ahk_id %LSide%
		Click, 650, 1285 Left, Down
		Sleep, 20
		Click, 650, 1285 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{v}{CtrlUp}
	Sleep, 20
	Send, {Enter}
	Gosub, ButtonA
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return

; DropG
F23::
	BlockInput, MouseMove
	Gui LSide: Submit, NoHide
		Clipboard := GstripColor
		ClipWait, 0,
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 229 Left, Down
		Sleep, 20
		Click, 2506, 239 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Send, %Clipboard%
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return
^F23::
	BlockInput, MouseMove
	Clipboard = 
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 230 Left, Down
		Sleep, 20
		Click, 2506, 230 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{c}{CtrlUp}
	ClipWait, 1
	Sleep, 50
	WinActivate, ahk_id %LSide%
		Click, 650, 1325 Left, Down
		Sleep, 20
		Click, 650, 1325 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{v}{CtrlUp}
	Sleep, 20
	Send, {Enter}
	Gosub, ButtonA
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0	
	BlockInput, MouseMoveOff
	return

; DropB
F24::
	BlockInput, MouseMove
	Gui LSide: Submit, NoHide
		Clipboard := BstripColor
		ClipWait, 0,
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 229 Left, Down
		Sleep, 20
		Click, 2506, 239 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Send, %Clipboard%
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return
^F24::
	BlockInput, MouseMove
	Clipboard = 
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 230 Left, Down
		Sleep, 20
		Click, 2506, 230 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{c}{CtrlUp}
	ClipWait, 1
	Sleep, 50
	WinActivate, ahk_id %LSide%
		Click, 650, 1370 Left, Down
		Sleep, 20
		Click, 650, 1370 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{v}{CtrlUp}
	Sleep, 20
	Send, {Enter}
	Gosub, ButtonA
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return

;	Clipboard = 
#IfWinActive ahk_id LSide
	*NumpadEnter::
	 	Gosub, ButtonA
		Return
	*Enter::
		Gosub, ButtonA
		Return
#IfWinActive

; #IfWinActive ahk_id NSide
; 	NumpadEnter::
; 	 	Gosub, ButtonB
; 		Return
; 	Enter::
; 		Gosub, ButtonB
; 		Return
; #IfWinActive
; Return

Esc::ExitApp
I realize I'm doing a lot wrong in the initial code above with the guis, but the color labels did work for me that way. Admittedly a lot of the functionality for this GUI is aesthetic, but it's to supplement a 1400 line script on mouse remapping and the charts/key visualizers are essential for it so I don't have to remember all 70 shortcuts. I'd like it to stylistically look like this:

Image

I can make graphics for anything but I don't know of good approaches. The functionality from top to bottom is the mouse charts then key visualizers, then a batch number I'd use to append to the title in a cloned save to ensure having backups, below would be a number for stroke and offset effects, then a number I'm hoping I can control Loops with to send the arrow keys a specific number of times for moving shapes and transformations, then finally the three hex value edits and their color labels. I'm having a hard time making an Edit box without a border, or placing a transparent image with a border above the edit boxes to give a graphical overlay without compromising being able to easily access the Edit box itself. It's obviously not essential but I've seen a lot of struggles trying to do this through searches without many clear (or rather, simple) solutions. Any advice or suggestions to make the code better when you have time?
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.

Post by just me » 09 Nov 2017, 04:05

Hi Off Topic,

just a first note:

AFAICS, your complete 'Sidebar' GUI consists of the following parts:
  1. A Pic control with changing content dependend on the state of LControl, LAlt, and LShift keys (MouseGUI).
  2. An area of three controls indicating the state of this keys (ModGUI).
  3. An area used for some settings (NumberGUI).
  4. An area to set colors (EditGUI).
As yet I don't see any reason to not combine all parts in one GUI.

1.Related to key states (not tested):
You don't have problems to create images. So if you don't need to reflect the current colors of the EditGUI to indicate the modifier states, you might use some nice Pic controls and GuiControl, Hide/Show to hide/show them accordingly to the key states, for example:

Code: Select all

; Hotkeys to trigger the ModGUIsub
~*LControl::
   GuiControl, Show, CtrlPressed
   CtrlState := "D"
   Gosub, KeyChecker
Return

~*LControl Up::
   GuiControl, Hide, CtrlPressed
   CtrlState :=  ""
   Gosub, KeyChecker
Return

; Update the MouseGUIsub charts
KeyChecker:
   if ( (AltState = "D") && (CtrlState = "D") && (ShiftState = "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_keymap.png
   Else if ( (AltState = "D") && (CtrlState = "D") && (ShiftState != "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_^!.png
   Else if ( (AltState = "D") && (CtrlState != "D") && (ShiftState = "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_+!.png
   Else if ( (AltState != "D") && (CtrlState = "D") && (ShiftState = "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_^+.png
   Else if ( (AltState != "D") && (CtrlState = "D") && (ShiftState = "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_^+.png
   Else if ( (AltState != "D") && (CtrlState != "D") && (ShiftState = "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_+.png
   Else if ( (AltState != "D") && (CtrlState = "D") && (ShiftState != "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_^.png
   Else if ( (AltState = "D") && (CtrlState != "D") && (ShiftState != "D") )
      GuiControl, MouseGUI:, MyPic, MyTmGui_!.png
   Else
      GuiControl, MouseGUI:, MyPic, MyTmGui_def.png
return
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.

Post by just me » 09 Nov 2017, 05:47

2. Related to the color Edit controls (tested):

You can change the background color of the Edit controls by specifying the ControlColor option of the Gui, Color, ... command. But this will also affect some other control types. If this is unwanted, there are other options to set individual background and text colors for Edit controls.

If you want to remove the frame, you can specify -E0x200 in the Edit control's options, but you have to adjust the position of the control in this case.

To update the Progress controls by pressing Return within the Edit controls, you might want to use a context-sensitive hotkey:

Code: Select all

Gui, +AlwaysOnTop +Border -Caption +Owner hwndGuiID ; GuiID is used for the context-sensitive hotkeys
Gui, Margin , 2, 2
Gui, Font, s8 q4, Arial
Gui, Color, 373737, 373737 ; the second value will set the background color for the Edit controls

;	I thought this would be a better option, but my progress control flashes white once I change the text, doesn't refresh color

Gui, Add, Progress, xm w12 h20 BackgroundD44400 vRshifter
Gui, Add, Edit, x+3 yp w50 h50 Limit6 Uppercase -Multi cWhite vRstripColor, d44400
Gui, Add, Progress, xm w12 h20 Background24EE49 vGshifter
Gui, Add, Edit, x+3 yp w50 h20 Limit6 Uppercase -Multi cWhite vGstripColor hwndG, 24ee49
Gui, Add, Progress, xm w12 h20 Background5064F1 vBshifter
Gui, Add, Edit, x+3 yp w50 h20 Limit6 Uppercase -Multi cWhite vBstripColor hwndB, 5064f1
Gui, Show, ; x575 y1270
Return

GuiEscape:
ExitApp

; Context-sensitive hotkeys, will be triggered only if the Gui is active and one of the Edit controls has the focus
#If WinActive("ahk_id " . GuiID) && (EditVar := ColorEditHasFocus())
Return::
   EditClr := SubStr(EditVar, 1, 1)                   ; Progress and Edit variable names share the first letter
   GuiControlGet, HexClr, , %EditVar%                 ; get the contents of the Edit control
   GuiControl, +Background%HexClr%, %EditClr%shifter  ; change the backgroung color of the related Progress control
Return
#If ; end of context-sensitive hotkeys

; Function to get the name of the variable assigned to the focused Edit control, if any
ColorEditHasFocus() {
   Static ColorEdits := "RstripColor,GstripColor,BstripColor"
   GuiControlGet, FocusVar, FocusV
   If FocusVar In %ColorEdits%
      Return FocusVar
}
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Re: Unreliable results changing GUI color on keypress.

Post by Off Topic » 11 Nov 2017, 20:57

just me wrote:Hi Off Topic,

just a first note:

AFAICS, your complete 'Sidebar' GUI consists of the following parts:
  1. A Pic control with changing content dependend on the state of LControl, LAlt, and LShift keys (MouseGUI).
  2. An area of three controls indicating the state of this keys (ModGUI).
  3. An area used for some settings (NumberGUI).
  4. An area to set colors (EditGUI).
As yet I don't see any reason to not combine all parts in one GUI.


Real gui results so far:
Image

Sorry for the late reply, trying to opt for a good one rather than a timely one. I felt like there was a lot to learn in just those two snippets, and after a while of struggling to get both working simultaneously in my old script (user errors), decided to rebuild everything in a single gui like you've suggested (which is a much better way to do things). I appreciate the help, everything works in my new script with exception to being able to submit for the color strips to update during a hotkey. I've tried a few different approaches to no success; I can manually activate the edit then write a hex color and press enter manually for a successful color update, I can even target the gui with focus through a hotkey then hit enter manually to success, but nothing within a hotkey sequence while sending enter and I don't understand why. [Line 299 in "DropR"]

I also had a mysterious blue color appear when I tried to change your function to affect the foreground color of the progress rather than the background. I edited the function and the control to what I expect would work, and it did have it working--but I couldn't get the background to reappear and my progress control is strangely blue on startup which I don't understand. I wanted to use the background as the border or frame by keeping it a static grey (#2B2B2B) but I had to work around it by adding borders to the image underlay beneath.

I've taken care of everything else to try and learn more about AHK, but I'd still appreciate a look over what I'm doing if you have time. From lines 268-430, I'm copying data to then paste into the hex edits or vice versa into Illustrator panels, but the only way I know to do this is through my clipboard. I suspect there'd be a better way than GuiControlGet > Clipboard then Clipboard > AI Panel and it's not an interruption but it'd be nice to retain previous clipboard contents without clearing them in case they're shapes or objects within Illustrator. I'm including the full script below, also a link to Google Drive containing all the assets and a zip with everything bundled.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, Force

mainProg := "illustrator"
mask = 373737
frame = 434343
Ctext = D5D5D5

; Gui
	;Settings
		Gui, +AlwaysOnTop +Border -Caption +Owner hwndGuiID ; GuiID is used for the context-sensitive hotkeys
		Gui, Margin , 2, 5
		Gui, Font, s8 q4, Arial
		Gui, Color, %mask%, 2c2c2c ; the second value will set the background color for the Edit controls
			Gui +LastFound
			WinSet, TransColor, %Mask%
	;Header
		Gui, Add, Picture, , mytmodHead.png
	;Mouse Underlay
		Gui, Add, Picture, yp+10 vMyPic, MyTmGui_def.png
	;Mouse Keys
		Gui, Add, Picture, xm+13 ym+15 vmLButton, mytmouseBig.png
			GuiControl, Hide, mLButton
		Gui, Add, Picture, xm+49 ym+15 vmRButton, mytmouseBig.png
			GuiControl, Hide, mRButton
		Gui, Add, Picture, xm+2 ym+36 vmF13, mytmouseMini.png
			GuiControl, Hide, mF13
		Gui, Add, Picture, xm+13 ym+36 vmF14, mytmouseMini.png
			GuiControl, Hide, mF14
		Gui, Add, Picture, xm+31 ym+33 vmMButton, mytmouseMedium.png
			GuiControl, Hide, mMButton
		Gui, Add, Picture, xm+13 ym+47 vmF15, mytmouseMedium.png
			GuiControl, Hide, mF15
		Gui, Add, Picture, xm+31 ym+47 vmF16, mytmouseMedium.png
			GuiControl, Hide, mF16
		Gui, Add, Picture, xm+49 ym+47 vmF17, mytmouseMedium.png
			GuiControl, Hide, mF17
		Gui, Add, Picture, xm+13 ym+62 vmXButton2, mytmouseMedium.png
			GuiControl, Hide, mXButton2
		Gui, Add, Picture, xm+31 ym+62 vmXButton1, mytmouseMedium.png
			GuiControl, Hide, mXButton1
		Gui, Add, Picture, xm+49 ym+62 vmF18, mytmouseMedium.png
			GuiControl, Hide, mF18
	;Divider
		Gui, Add, Picture, xp-49 yp+20, mytmodDiv.png
	;Mod Keys
		Gui, Add, Picture, xp+7 yp+10 c%Rc% background0x%Mask% , myTmod+down.png
			Gui, Add, Picture, yp c%Rc% background0x%Mask% vMyShiftUp, myTmod+up.png
		Gui, Add, Picture, yp+16 c%Gc% background0x%Mask% vMyCtrlDown, myTmod^down.png
			Gui, Add, Picture, yp c%Gc% background0x%Mask% vMyCtrlUp, myTmod^up.png
		Gui, Add, Picture, xp+25 yp c%Bc% background0x%Mask% vMyAltDown, myTmod!down.png
			Gui, Add, Picture, xp yp c%Bc% background0x%Mask% vMyAltUp, myTmod!up.png
	;Bottom Underlay	
		Gui, Add, Picture, xp-34 yp+22 , mytmodBottom.png
	;Settings (Offset, Angle, # of Loops)
		;Gui, Add, Edit, xp+36 yp+11 w27 h13 Limit4 Uppercase -Multi -E0x200 c%Ctext% vBatchNo, 1.36
		Gui, Add, Edit, Limit1 xp+6 yp+8 w28 h13 -E0x200 -VScroll c%Ctext% vOffsetN +WantReturn,
			Gui, Add, UpDown, c2c2c2c Hidden vScrollBoxA , 2    ; ClassNN msctls_updown321
			Gui, Add, Picture, xp+17 yp , mytmodNumArrows2.png
		Gui, Add, Edit, Limit3 xp-18 yp+21 w22 h12 -E0x200 -VScroll c%Ctext% vAngleN +WantReturn, 135
			Gui, Add, Picture, xp+22 yp , mytmodNumDeg.png
			; Gui, Add, UpDown, c2c2c2c vScrollBoxA , 2    ; ClassNN {msctls_updown321}
		Gui, Add, Edit, Limit1 xp-22 yp+21 w28 h13 -E0x200 -VScroll c%Ctext% vLoopN +WantReturn,
			Gui, Add, UpDown, c2c2c2c Hidden vScrollBoxB , 5    ; ClassNN msctls_updown322
			Gui, Add, Picture, xp+17 yp , mytmodNumArrows2.png
	;Hex Color strips
		; The below produces a mysterious blue color, not sure where it's coming from
		; Gui, Add, Progress, xm+2 yp+150 w10 h12 Background%frame% cd44400 vRshifter, 100
		Gui, Add, Progress, xm+2 yp+28 w10 h12 Backgroundd44400 vRshifter,
			Gui, Add, Edit, x+3 yp w50 h12 Limit6  Uppercase -Multi -E0x200 c%Ctext% vRstripColor, d44400
		Gui, Add, Progress, xm+2 yp+19 w10 h12 Background24EE49 vGshifter
			Gui, Add, Edit, x+3 yp w50 h12 Limit6 Uppercase -Multi -E0x200 c%Ctext% vGstripColor, 24ee49
		Gui, Add, Progress, xm+2 yp+19 w10 h12 Background5064F1 vBshifter
			Gui, Add, Edit, x+3 yp w50 h12 Limit6 Uppercase -Multi -E0x200 c%Ctext% vBstripColor, 5064f1
	Gui, Show, x571 y975
	Return

; KeyLights (Mouse)
	~*LButton::
	   	GuiControl, Show, mLButton
		Return
	~*LButton Up::
	   	GuiControl, Hide, mLButton
		Return
	~*RButton::
	   	GuiControl, Show, mRButton
		Return
	~*RButton Up::
	   	GuiControl, Hide, mRButton
		Return
	~*F13::
	   	GuiControl, Show, mF13
		Return
	~*F13 Up::
	   	GuiControl, Hide, mF13
		Return
	~*F14::
	   	GuiControl, Show, mF14
		Return
	~*F14 Up::
	   	GuiControl, Hide, mF14
		Return
	~*MButton::
	   	GuiControl, Show, mMButton
		Return
	~*MButton Up::
	   	GuiControl, Hide, mMButton
		Return
	~*F15::
	   	GuiControl, Show, mF15
		Return
	~*F15 Up::
	   	GuiControl, Hide, mF15
		Return
	~*F16::
	   	GuiControl, Show, mF16
		Return
	~*F16 Up::
	   	GuiControl, Hide, mF16
		Return
	~*F17::
	   	GuiControl, Show, mF17
		Return
	~*F17 Up::
	   	GuiControl, Hide, mF17
		Return
	~*XButton1::
	   	GuiControl, Show, mXButton1
		Return
	~*XButton1 Up::
	   	GuiControl, Hide, mXButton1
		Return
	~*XButton2::
	   	GuiControl, Show, mXButton2
		Return
	~*XButton2 Up::
	   	GuiControl, Hide, mXButton2
		Return
	~*F18::
	   	GuiControl, Show, mF18
		Return
	~*F18 Up::
	   	GuiControl, Hide, mF18
		Return

; KeyLights (Modifiers)
	~*LControl::
	   	GuiControl, Hide, MyCtrlUp
	   	GuiControl, Show, MyCtrlDown
	    CtrlState := "D"
	    Gosub, KeyChecker
	Return
	~*LControl Up::
	   GuiControl, Hide, MyCtrlDown
	   GuiControl, Show, MyCtrlUp
	   CtrlState :=  ""
	   Gosub, KeyChecker
	Return

	~*LShift::
	   GuiControl, Hide, MyShiftUp
	   GuiControl, Show, MyShiftDown
	   ShiftState := "D"
	   Gosub, KeyChecker
	Return
	~*LShift Up::
	   GuiControl, Hide, MyShiftDown
	   GuiControl, Show, MyShiftUp
	   ShiftState :=  ""
	   Gosub, KeyChecker
	Return

	~*LAlt::
	   GuiControl, Show, MyAltDown
	   GuiControl, Hide, MyAltUp
	   AltState := "D"
	   Gosub, KeyChecker
	Return
	~*LAlt Up::
	   GuiControl, Hide, MyAltDown
	   GuiControl, Show, MyAltUp
	   AltState :=  ""
	   Gosub, KeyChecker
	Return

; Update the MouseGUIsub charts
KeyChecker:
   if ( (AltState = "D") && (CtrlState = "D") && (ShiftState = "D") )
      GuiControl, , MyPic, MyTmGui_keymap.png
   Else if ( (AltState = "D") && (CtrlState = "D") && (ShiftState != "D") )
      GuiControl, , MyPic, MyTmGui_^!.png
   Else if ( (AltState = "D") && (CtrlState != "D") && (ShiftState = "D") )
      GuiControl, , MyPic, MyTmGui_+!.png
   Else if ( (AltState != "D") && (CtrlState = "D") && (ShiftState = "D") )
      GuiControl, , MyPic, MyTmGui_^+.png
   Else if ( (AltState != "D") && (CtrlState = "D") && (ShiftState = "D") )
      GuiControl, , MyPic, MyTmGui_^+.png
   Else if ( (AltState != "D") && (CtrlState != "D") && (ShiftState = "D") )
      GuiControl, , MyPic, MyTmGui_+.png
   Else if ( (AltState != "D") && (CtrlState = "D") && (ShiftState != "D") )
      GuiControl, , MyPic, MyTmGui_^.png
   Else if ( (AltState = "D") && (CtrlState != "D") && (ShiftState != "D") )
      GuiControl, , MyPic, MyTmGui_!.png
   Else
      GuiControl, , MyPic, MyTmGui_def.png
return

GuiEscape:
ExitApp

; Context-sensitive hotkeys, will be triggered only if the Gui is active and one of the Edit controls has the focus
#If WinActive("ahk_id " . GuiID) && (EditVar := ColorEditHasFocus())
Return::
   EditClr := SubStr(EditVar, 1, 1)                   ; Progress and Edit variable names share the first letter
   GuiControlGet, HexClr, , %EditVar%                 ; get the contents of the Edit control
   GuiControl, +Background%HexClr%, %EditClr%shifter  ; change the background color of the related Progress control
   ; The mysterious blue color comes when switching the line above to this:
   ; GuiControl, +Background +c%HexClr%, %EditClr%shifter ; It will change color but the background won't respawn/reshow/reactivate
Return
#If ; end of context-sensitive hotkeys

; Function to get the name of the variable assigned to the focused Edit control, if any
ColorEditHasFocus() {
   Static ColorEdits := "RstripColor,GstripColor,BstripColor"
   GuiControlGet, FocusVar, FocusV
   If FocusVar In %ColorEdits%
      Return FocusVar
}


^Tab::
	GuiControl, Focus, Edit1
	WinActivate, ahk_id %GuiID%
	Return

; Reset RGB
F21::
	BlockInput, MouseMove
	; WinActivate, ahk_id %GuiID%
	; WinActivate, ahk_exe AutoHotkey.exe
	Sleep, 50
		Click, 625, 1307 Left, Down
		Sleep, 20
		Click, 625, 1307 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Sleep, 20
	SendInput, d44400
	Sleep, 20
	Send, {Tab}
	Sleep, 20
	SendInput, 24ee49
	Sleep, 20
	Send, {Tab}
	Sleep, 20
	SendInput, 5064f1
	Sleep, 20
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return 

; DropR
F22::
	BlockInput, MouseMove
	Gui, Submit, NoHide
			Clipboard := RstripColor
		ClipWait, 0,
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 229 Left, 
		Click, 2506, 239 Left, 
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Sleep, 50
	Send, %Clipboard%
	Sleep, 50
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return
^F22::
	; BlockInput, MouseMove
	Clipboard = 
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 230 Left, Down
		Sleep, 20
		Click, 2506, 230 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{c}{CtrlUp}
	ClipWait, 1
	Sleep, 50
	; Tried to activate GUI, replace contents, hit Enter to submit
		; WinActivate, ahk_id %GuiID%
		; GuiControl, , Edit4, %Clipboard%
		; Sleep, 50
		; Send, {Enter}
		; Sleep, 50
	; Tried to activate focus on control, hit Enter and submit
		; GuiControl, Focus, Edit4
		; Sleep, 50
		; Send, {Enter}
	; Tried to click the edit control, hit enter and submit
		; 	Click, 625, 1304 Left, Down
		; 	Sleep, 20
		; 	Click, 625, 1304 Left, Up
		; 	Sleep, 20
		; Send, {CtrlDown}{a}{CtrlUp}
			; Sleep, 20
		; Send, {Enter}
	; Tried duplicating your context sensitive function, put it in a label and using gosub
		; gosub ReturnDupe
		; Gui, Submit, NoHide
	; Tried using "return" instead of "enter", vice versa, even changing the hotkey here and in the
	; function to another keyboard key entirely, still doesn't work?
		; Send, {Return}
	; It will change if I stop at the focus then manually hit enter, but not when I simulate/send an enter?
	WinActivate, ahk_id %GuiID%
	Sleep, 50
	Send, {CtrlDown}{Tab}{CtrlUp}
	Sleep, 50
	Send, {Tab}{Tab}{Tab}
	Sleep, 50
	Send, %Clipboard%
	Sleep, 50
	Send, {Enter} ; I can get a message box after this line but the colors still don't change
	Sleep, 20
;   MsgBox, Where are you, Enter?
;	Gui, Submit, NoHide
	; WinActivate, ahk_class %mainProg%
	; 	Sleep, 50
	; 	Click, 1280, 720, 0
	; BlockInput, MouseMoveOff
	return

; DropG
F23::
	BlockInput, MouseMove
	Gui, Submit, NoHide
		Clipboard := GstripColor
		ClipWait, 0,
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 229 Left, 
		Click, 2506, 239 Left, 
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Sleep, 50
	Send, %Clipboard%
	Sleep, 50
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return
^F23::
	BlockInput, MouseMove
	Clipboard = 
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 230 Left, Down
		Sleep, 20
		Click, 2506, 230 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{c}{CtrlUp}
	ClipWait, 1
	Sleep, 50
	WinActivate, ahk_id %GuiID%
	GuiControl, , Edit5, %Clipboard%
	Sleep, 20
	GuiControl, Focus, Edit5
	Sleep, 20
	Send, {Enter}
	Gui, Submit, NoHide
	Sleep, 20
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0	
	BlockInput, MouseMoveOff
	return

; DropB
F24::
	BlockInput, MouseMove
	Gui, Submit, NoHide
		Clipboard := BstripColor
		ClipWait, 0,
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 229 Left, Down
		Sleep, 20
		Click, 2506, 239 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{CtrlUp}
	Send, %Clipboard%
	Send, {Enter}
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return
^F24::
	BlockInput, MouseMove
	Clipboard = 
	WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436
		Click, 2506, 230 Left, Down
		Sleep, 20
		Click, 2506, 230 Left, Up
		Sleep, 20
	Send, {CtrlDown}{a}{c}{CtrlUp}
	ClipWait, 1
	Sleep, 50
	WinActivate, ahk_id %GuiID%
	GuiControl, , Edit6, %Clipboard%
	Sleep, 20
	GuiControl, Focus, Edit6
	Sleep, 20
	Send, {Enter}
	Sleep, 20
	Gui, Submit, NoHide
	Sleep, 50
	WinActivate, ahk_class %mainProg%
		Sleep, 50
		Click, 1280, 720, 0
	BlockInput, MouseMoveOff
	return

; Loops
;Left
*$+!XButton2::
	; BlockInput, On
   	GuiControl, Show, mXButton2
	Sleep, 50
	; Send, {LAlt Up}{LShift Up}
	Gui, Submit, NoHide
	Clipboard := LoopN
	ClipWait, 0
	Loop, %clipboard% 
		{ 
		Send, {Left}
		Sleep, 50
		} 
	; Send, {LAlt Down}{LShift Down}
	GuiControl, Hide, mXButton2
	; BlockInput, Off
		Return
;Right
*$+!XButton1::
	; BlockInput, On
   	GuiControl, Show, mXButton1
	Sleep, 50
	; Send, {LAlt Up}{LShift Up}
	Gui, Submit, NoHide
	Clipboard := LoopN
	ClipWait, 0
	Loop, %clipboard% 
		{ 
		Send, {Right}
		; Sleep, 50
		}
	GuiControl, Hide, mXButton1
	; BlockInput, Off
		Return
;Up
*$+!F15::
	; BlockInput, On
   	GuiControl, Show, mF15
	Sleep, 50
	; Send, {LAlt Up}{LShift Up}
	Gui, Submit, NoHide
	Clipboard := LoopN
	ClipWait, 0
	Loop, %clipboard% 
		{ 
		Send, {Up}
		; Sleep, 50
		}
   	GuiControl, Hide, mF15
	; BlockInput, Off
		Return
;Down
*$+!F16::
	; BlockInput, On
  	GuiControl, Show, mF16
	Sleep, 50
	; Send, {LAlt Up}{LShift Up}
	Gui, Submit, NoHide
	Clipboard := LoopN
	ClipWait, 0
	Loop, %clipboard% 
		{
		Send, {Down}
		; Sleep, 20
		}
  	GuiControl, Hide, mF16
	; BlockInput, Off
		Return
;Redo
*^+F15::
	Gui, Submit, NoHide
	GuiControl, Show, mF15
	Clipboard := LoopN
	ClipWait, 0
	Loop, %clipboard% 
		{ 
		Send, {CtrlDown}{d}{CtrlUp}
		; Sleep, 20
		} 
		GuiControl, Hide, mF15
		Return
;RedoClone
*^+F16:: 
	GuiControl, Show, mF16
	Gui, Submit, NoHide
	Clipboard := LoopN
	ClipWait, 0
	Loop, %clipboard% 
		{ 
		; Will produce clones at end, glitched
		; Send,  {CtrlUp}{ShiftDown}{F7 Down}{ShiftUp}
		; Sleep, 20
		Send, {MButton}
		Sleep, 50
		Send, {CtrlDown}{d}{CtrlUp}
		Sleep, 20
		} 
		GuiControl, Hide, mF16
		Return

;RotationAngle
^+MButton::
	KeyWait, LControl
	KeyWait, LShift
	Gui, Submit, NoHide
	Clipboard := AngleN
	ClipWait, 0
	WinActivate, ahk_class %mainProg%
	Send, {r}
	Sleep, 20
	Send, {Enter}
	; WinWaitActive, Rotate
	; WinActivate, Rotate
	Sleep, 200
	Send, %Clipboard%
	Sleep, 20
	Send, {Enter}
	Sleep, 20
	WinActivate, ahk_class %mainProg%
	BlockInput, Off
	return

Esc::ExitApp
Lastly, without wearing out my welcome or hopefully appearing ungrateful, would it be impractical to simulate animation through changing GuiControl pictures every 40ms, 20ms, or 16.667 ms? I ask because I thought it'd be interesting to use loops containing GuiControls with png sequences that simulate 25 (or any I'd want) frames per second, so animations within loops that I could potentially break conditionally or have be interactive in some manner. I've seen that gifs are supported in gui displays but I don't see many discussions about using them interactively, and I'd specifically want to cushion animations like button presses with 3 to 5 frames to "ease in" or "ease out" of extreme poses when activated. If I could get away with it, I'd actually love to have multiple looping animations (which would be vector so very low data size and strict color profile, like my avatar or these icons in the gui) running on the gui but I'm not sure if it's pie in the sky or too cpu-intensive. Are there any examples that you've seen or know of, or any ways you think this would be best done? Avoiding flashing too?
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.

Post by just me » 12 Nov 2017, 05:59

Hi Off Topic,

no reason to apologize. I see you did much work in the meantime. I'll look at your script, but this might need some time. I cannot test here, because I don't have Illustrator and my display is much smaller than yours.

Some first questions:
1. Is the "Active Window Info (Window Spy" (contained in the AutoHotkey entry in the Start Menu) able to get Information about the Illustrator controls you want to change?
2. What are the WinActivate, ahk_class tooltips_class32 Hwnd0x2b0436 commands intended to do? Is it actually the correct class name?

If you want to update the related Progress control after you changed a color Edit using a hotkey, you don't need to send Enter/Return to the Edit. You know which Edit has been changed, so just update the correspondend Progress with the new value directly. Also, you should use the name of the associated variable instead of the ClassNN to access the controls.

To keep the current contents of the clipboard, store it before you empty the clipboard and restore it after you have done what you want:

Code: Select all

SavedClipboard:= ClipboardAll
Clipboard := ""
...
...
Clipboard := SavedClipboard
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Re: Unreliable results changing GUI color on keypress.

Post by Off Topic » 12 Nov 2017, 17:13

Thanks for the tips, changing the progress control seems obvious in retrospect, lol. That's also a very handy and simple way to retain the clipboard data, it's exactly what I'd needed.

1. Yes it is -- admittedly I was using a script that Leefme posted and I'd found in a search that displays HWND's in a tooltip to get the data. That was one of the first things I did with AHK and I was stabbing in the dark without knowing what to look for, but I now see that the specific Color edit box is listed as having the same exe (illustrator.exe) and class (illustrator) as my Illustrator edit window, explicitly says ClassNN Edit14.

2. I'm not sure if it's the correct class name after using Window Spy, which states the ClassNN as Edit14 instead. I'm trying to transfer the hexadecimal text from one of my gui's 3 hex edits to this Edit14 panel and vice versa in a way that wouldn't be an interruption to (or is too fast to interrupt me during) drawing in the edit window. I'm not sure if it had any effect since I was forcing a click after that WinActivate, but I didn't have errors so I kept it. I'm doing this in an admittedly crude way right now because I'm just sending my mouse there, clicking the edit box, copying/pasting the data then finishing by sending my mouse back to where it would likely have been before triggering the hotkey. I have the tab open and the edit box fixed in place so it's primitive and very simple, but it worked for me in the first iteration of my gui so I hadn't thought of updating to a better method. The panel on the rightside of my screen looks like this:

Image



In this speed drawing of a cube, I use the hex boxes at 0:30. Having this gui and using AHK is amazing for drawing with a mouse, it makes a world of difference in Illustrator.

No rush for replies. If I can make it easier for you in any way, feel free to say so.
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.

Post by just me » 13 Nov 2017, 03:38

O.K., please try the following to transfer from and to the RstripColor Edit (untested):

Code: Select all

; DropR
F22::
   BlockInput, MouseMove ; might not be needed
   GuiControlGet, RstripColor
   SetControlDelay, -1 ; might not be needed
   ControlSetText, Edit14, %RstripColor%, ahk_class %mainProg%
   ControlClick, Edit14, ahk_class %mainProg% ; if you need a click
   ControlSend, Edit14, {Enter}, ahk_class %mainProg% ; if you need an Enter keystroke
   BlockInput, MouseMoveOff ; might not be needed
Return
^F22::
   ControlGetText, HexColor, Edit14, ahk_class %mainProg%
   GuiControl, , RstripColor, %HexColor%
   GuiControl, +Background%HexColor%, Rshifter
Return
Does it work for you?
User avatar
Off Topic
Posts: 43
Joined: 07 Oct 2017, 20:57

Re: Unreliable results changing GUI color on keypress.

Post by Off Topic » 13 Nov 2017, 13:58

Wow, that's an incredibly direct way to do it. Thanks! I'll use that method for quite a bit going forward, I must've overlooked that in searching. The first one did send the control the text but Illustrator thought I was trying to move an object rather than submit when it simulated enter, but I've gotten it working by setting the Focus to the control just before and sending a regular enter stroke because the ControlSend didn't seem to work for me. So I now have:

Code: Select all

; DropR
F22::
   GuiControlGet, RstripColor
   ControlFocus, Edit14, ahk_class %mainProg%
   ControlSetText, Edit14, %RstripColor%, ahk_class %mainProg%
   Send, {Enter}
Return
^F22::
   ControlGetText, HexColor, Edit14, ahk_class %mainProg%
   GuiControl, , RstripColor, %HexColor%
   GuiControl, +Background%HexColor%, Rshifter
Return
Makes a huge difference! It's really stunning how well that works -- I even tried it when the panels are minimized and it still reliably sends. Can't thank you enough, that will actually take care of me because I'm about to dive in real deep with using these examples in other contexts. So thanks for your time, my script is flawless at the moment, it's way better than I'd expected to make when I first started and using it in conjuction with Illustrator has really helped me in the learning curve. Feel free to knock if you're in need of vectors, icons, graphics, or animation, etc, and I'll happily oblige. I only have one or two more problems but I'm pretty sure I can solve them myself using these snippets and referencing the guide. Really appreciate all the help and expertise though, goes a long way in helping to encourage use (even though most answers are right in front of you in the Help Guide if you know where to look, there's so much text that it can be kind of overwhelming especially if not one who performs too well in that very literary style of learning).
just me
Posts: 5510
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Unreliable results changing GUI color on keypress.

Post by just me » 14 Nov 2017, 02:50

I'm pleased I could help you. If you need further help, post your current version of the script or the problematic parts. I'll have a look, then.
Post Reply

Return to “Ask For Help”