Change Background Color of a Gui Hotkey Control. Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Change Background Color of a Gui Hotkey Control.

28 May 2019, 05:02

How would I go about changing the background color of a Hotkey Gui control?

Code: Select all


#SingleInstance,Force

Gui,Add,Hotkey,

Gui,Show,w200 h100

return
GuiClose:
	ExitApp

Edit, I guess font color too.
iPhilip
Posts: 409
Joined: 02 Oct 2013, 12:21

Re: Change Background Color of a Gui Hotkey Control.

29 May 2019, 13:20

It looks like the Hotkey control does not allow custom background or font colors:

Code: Select all

Gui, Font, cWhite
Gui, Color, Black, Blue
Gui,Add,Hotkey, , ^c
Gui,Add,Edit, , hello world
Gui,Show,w200 h100
return
GuiClose:
	ExitApp
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Re: Change Background Color of a Gui Hotkey Control.

29 May 2019, 16:54

iPhilip wrote:
29 May 2019, 13:20
It looks like the Hotkey control does not allow custom background or font colors:

Code: Select all

Gui, Font, cWhite
Gui, Color, Black, Blue
Gui,Add,Hotkey, , ^c
Gui,Add,Edit, , hello world
Gui,Show,w200 h100
return
GuiClose:
	ExitApp
I was thinking more along the lines of through the windows api using dllcalls but the feedback I get from "Just me" suggests that it's likely more trouble than it's worth.

It's a shame, I like darker themed guis and the hotkey control sticks out like a sore thumb on them.


SnapShot_495.png
SnapShot_495.png (214.57 KiB) Viewed 858 times
rommmcek
Posts: 656
Joined: 15 Aug 2014, 15:18

Re: Change Background Color of a Gui Hotkey Control.

30 May 2019, 20:15

Hi Hellbend!
Your Gui designs are fantastic! iPhilip suggested using Edit Control. I found the script I believe has a potential to replace Hotkey Control with Edit. I don't have time (and knowledge) to finish it, but with help of other members might be doable.
Spoiler
Bye!
Attachments
Original Script.ahk
(1.83 KiB) Downloaded 11 times
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Re: Change Background Color of a Gui Hotkey Control.

31 May 2019, 00:31

rommmcek wrote:
30 May 2019, 20:15
Hi Hellbend!
Your Gui designs are fantastic! iPhilip suggested using Edit Control. I found the script I believe has a potential to replace Hotkey Control with Edit. I don't have time (and knowledge) to finish it, but with help of other members might be doable.
Spoiler
Bye!
Thank you.

I have considered using just a plain ol' edit for hotkeys, and it would be simple enough to implement.

The problem is that I'm often not the end user and explaining the rules to follow when typing in a hotkey would no doubt lead to loads of people complaining that "It's too complicated", which happens even without the extra layer of complexity. (Even the gui I posted a image of will be "Too Complicated" for some people)

The code you posted above shows some promise with idiot proofing, but as you pointed out it's not finished (From what I can tell, it currently doesn't work at all, and is full of bugs). I don't know anything about regex, it's something that I've tried to force myself to learn, but I find working with text to be beyond boring and my brain always says "F you Hellbent, I'm not sitting here doing this boring a** sh**, I'm going to think about boobs or something... anything... other than this, peace I'm out! (start blank stare)". True story.

So I guess that rules me out of trying to get it to work :lol:
rommmcek
Posts: 656
Joined: 15 Aug 2014, 15:18

Re: Change Background Color of a Gui Hotkey Control.

02 Jun 2019, 23:20

Looks like nobody is interested. I guess it's wrong season (examens and pre-holydays time).
It was just a (one) hint how could be done. But the script itself seems not to detect multiple keys when pressed (almost) simultaneously. That's why I attempted to assign all possible Hotkeys, but before finishing (lacks modifier keys feedback too), I found a very sophisticated script. I'm posting quick modification.
Attachments
Hotkey Edit 2.0.ahk
(6.2 KiB) Downloaded 12 times
Key Hystory 2.ahk
(12.03 KiB) Downloaded 13 times
rommmcek
Posts: 656
Joined: 15 Aug 2014, 15:18

Re: Change Background Color of a Gui Hotkey Control.  Topic is solved

03 Jun 2019, 09:34

This code is simple and works pretty good.

Code: Select all

#NoEnv
#SingleInstance,Force

Gui, +hwndHw
Gui, Color, d0c060, 4444444
Gui, Font, s14 cffff00 TAhoma
Gui,Add,Hotkey, W280 x10 y6 vEdt1 gEdt1 hwndHedt1
Gui,Add,Edit, x10 y6 w280 vEdt2 hwndHedt2 Background00ffff, None
Gui,Show, x1300 y150

OnMessage(0x133, "Focus_Hk")
SetTimer, FcEdt, 250
return

Focus_Hk() {
    GuiControl, Focus, Edt1
}

FcEdt:
    if !WinActive("ahk_id " Hw)
        GuiControl, Focus, Edt2
return

Edt1:
    GuiControlGet, Ehk,, Edt1
    StringUpper, Ehk, Ehk , T
    Ehk:=StrReplace(Ehk, "`+", "Shift + "), Ehk:=StrReplace(Ehk, "`!", "Alt + "), Ehk:=StrReplace(Ehk, "`^", "Ctrl + ")
    if Ehk
        GuiControl,, Edt2, % Ehk
    else GuiControl,, Edt2, None
Return

^Esc::
GuiClose:
	ExitApp
P.s.: Timer should be replaced by a hook, but didn't want to sacrifice simplicity.
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Re: Change Background Color of a Gui Hotkey Control.

03 Jun 2019, 12:56

rommmcek wrote:
03 Jun 2019, 09:34
This code is simple and works pretty good.
lol I love the approach :bravo:
I'm kind of ashamed that I didn't think of doing it this way myself. :oops:
I have taken a similar approach before when using edits on a Layered window.
Thank you very much for your time, this should come in handy.
iPhilip
Posts: 409
Joined: 02 Oct 2013, 12:21

Re: Change Background Color of a Gui Hotkey Control.

04 Jun 2019, 01:53

Here is a similar but simpler implementation of the above:

Code: Select all

#NoEnv

Gui, Font, cWhite
Gui, Color, Red, Black
Gui, Add, Hotkey, vHotkeyCtrl gHotkeyCtrlEvent
Gui, Add, Edit, yp vEditCtrl
HotkeyCtrlEvent()
Gui, Show
OnMessage(0x06, "HotkeyCtrlEvent")  ; WM_ACTIVATE = 0x06
Return

HotkeyCtrlEvent() {
   GuiControlGet, HotkeyCtrl
   HotkeyCtrl := Format("{:T}", HotkeyCtrl)
   HotkeyCtrl := StrReplace(HotkeyCtrl, "+", "Shift + ")
   HotkeyCtrl := StrReplace(HotkeyCtrl, "^", "Ctrl + ")
   HotkeyCtrl := StrReplace(HotkeyCtrl, "!", "Alt + ")
   GuiControl, , EditCtrl, % HotkeyCtrl ? HotkeyCtrl : "None"
}

GuiClose:
	ExitApp
Cheers!
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Re: Change Background Color of a Gui Hotkey Control.

04 Jun 2019, 02:15

iPhilip wrote:
04 Jun 2019, 01:53
Here is a similar but simpler implementation of the above:
Cheers!
It works perfectly as far as I can tell.

Code: Select all

#SingleInstance,Force
#NoEnv

Hotkey,% MyHotkey:="Numpad1",HKPress

Gui, Font, cWhite
Gui, Color, Red, Black
Gui, Add, Hotkey, vHotkeyCtrl gHotkeyCtrlEvent,% MyHotkey
Gui, Add, Edit, yp vEditCtrl
HotkeyCtrlEvent()
Gui,Add,Button,gUpdateHK,Update
Gui, Show
OnMessage(0x06, "HotkeyCtrlEvent")  
Return

GuiClose:
	ExitApp
	
UpdateHK:
	GuiControlGet,New_Hotkey,,HotkeyCtrl
	if(New_Hotkey!=MyHotkey&&New_Hotkey){
		Hotkey,% MyHotkey,HKPress,Off
		Hotkey,% MyHotkey:=New_Hotkey,HKPress,On
	}
	return
	
HKPress:
	loop 3
		soundbeep,% (A_Index=1)?(Beep:="500"):(Beep+=200)
	return
	
HotkeyCtrlEvent() {
   GuiControlGet, HotkeyCtrl
   HotkeyCtrl := Format("{:T}", HotkeyCtrl)
   HotkeyCtrl := StrReplace(HotkeyCtrl, "+", "Shift + ")
   HotkeyCtrl := StrReplace(HotkeyCtrl, "^", "Ctrl + ")
   HotkeyCtrl := StrReplace(HotkeyCtrl, "!", "Alt + ")
   GuiControl, , EditCtrl, % HotkeyCtrl ? HotkeyCtrl : "None"
}	
Thanks.
rommmcek
Posts: 656
Joined: 15 Aug 2014, 15:18

Re: Change Background Color of a Gui Hotkey Control.

04 Jun 2019, 10:52

@iPhilip: Great condensed rewrite!

One thing remains: In a Gui with multiple controls can underlaying Hotkey control quite often pop up when manually changing the focus (via Tab key or mouse click)!
iPhilip
Posts: 409
Joined: 02 Oct 2013, 12:21

Re: Change Background Color of a Gui Hotkey Control.

04 Jun 2019, 11:23

rommmcek wrote:
04 Jun 2019, 10:52
One thing remains: In a Gui with multiple controls can underlaying Hotkey control quite often pop up when manually changing the focus (via Tab key or mouse click)!
@rommmcek Thank you for noticing that. The version below solves that problem:

Code: Select all

#NoEnv

Gui, Font, cWhite
Gui, Color, Red, Black
Gui, Add, Hotkey, vHotkeyCtrl gHotkeyCtrlEvent
Gui, Add, Edit, yp vEditCtrl
Gui, Add, Edit, , Text Field
HotkeyCtrlEvent()
Gui, Show
OnMessage(0x0F, "HotkeyCtrlEvent")  ; WM_PAINT = 0x0F
Return

HotkeyCtrlEvent() {
   GuiControlGet, HotkeyCtrl
   HotkeyCtrl := Format("{:T}", HotkeyCtrl)
   HotkeyCtrl := StrReplace(HotkeyCtrl, "+", "Shift + ")
   HotkeyCtrl := StrReplace(HotkeyCtrl, "^", "Ctrl + ")
   HotkeyCtrl := StrReplace(HotkeyCtrl, "!", "Alt + ")
   GuiControl, , EditCtrl, % HotkeyCtrl ? HotkeyCtrl : "None"
}

GuiClose:
	ExitApp
Cheers!
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
rommmcek
Posts: 656
Joined: 15 Aug 2014, 15:18

Re: Change Background Color of a Gui Hotkey Control.

04 Jun 2019, 11:37

Now sometimes focus sticks at overlaying Edit control, thus having unwanted effect.
Besides Sys key (Alt) invokes on my OS ugly system sound.
rommmcek
Posts: 656
Joined: 15 Aug 2014, 15:18

Re: Change Background Color of a Gui Hotkey Control.

04 Jun 2019, 17:48

Possible fix:

Code: Select all

#NoEnv
#SingleInstance,Force
global ShiftDown
; ...
OnMessage(0x0F, "HotkeyCtrlEvent")  ; WM_PAINT = 0x0F
OnMessage(0x100, "Wm_KeyDown")
OnMessage(0x101, "Wm_KeyUp")
Return
    
Wm_KeyDown(wp) {
    (wp=16)? ShiftDown:=1: ""
}

Wm_KeyUp(wp) {
    if (wp=9) {
        GuiControlGet, CFoc, Focus
        if (CFoc = "Edit1")
            if ShiftDown ;|| GetKeyState("Shift", "P")
                    GuiControl, Focus, HotkeyCtrl        
            else ;GuiControl, Focus, BtnCtrl ;-next (successive) Control
               ControlSend, % CFoc, {Tab}, % "ahk_id " WinExist("A")
     }
    if (wp=16)
         SetTimer, ClearShift, -50
}

ClearShift:
   ShiftDown:=""
return
; ….
Edit: Alternative for GuiControl, Focus, BtnCtrl ;-next (successive) Control would be: ControlSend, % CFoc, {Tab}, % "ahk_id " WinExist("A"), to render code more universal.
Edit2: Adding monitoring ShiftDown, so quick release of Shift key when backward Tabbing works too.
Edit3: Fixing ShiftDown reset.
by iPhilip
by Hellbend

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], deten, flyingDman, Getfree, humanix and 168 guests