Turn On high contrast mode with autohotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
downloaderfan
Posts: 34
Joined: 09 Jun 2017, 09:19

Turn On high contrast mode with autohotkey

11 Dec 2017, 05:08

Windows has a built in Alt+Shift+PrtScn to toggle into high contrast mode, but Send !+{PrintScreen} doesn't work. It seems that hotkey is protected from simulation. Someone suggested me to use dllcall with
SystemParametersInfo
SPI_SETHIGHCONTRAST
0x0043

Only problem is, I know nothing about dllcall & even googling didn't reveal any code to set high contrast mode. I'm running AHK 64, any help please?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Turn On high contrast mode with autohotkey  Topic is solved

11 Dec 2017, 05:30

This should do it. Cheers. Btw for anyone who wants to test, it was quite slow setting this to on, on my Windows 7 PC.

Code: Select all

q:: ;set high contrast on
vFlags := 0x1 ;on
;vFlags := 0x0 ;off
vSize := A_PtrSize=8?16:12
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
;HCF_HIGHCONTRASTON := 0x1
NumPut(vFlags, &HIGHCONTRAST, 4, "UInt") ;dwFlags
;SPI_SETHIGHCONTRAST := 0x43
DllCall("user32\SystemParametersInfo", UInt,0x43, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
return
Link:
See if High Contrast Theme is On -- Help with DllCall("SystemParametersInfo") - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38972
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
downloaderfan
Posts: 34
Joined: 09 Jun 2017, 09:19

Re: Turn On high contrast mode with autohotkey

11 Dec 2017, 05:33

jeeswg wrote:This should do it. Cheers. Btw for anyone who wants to test, it was quite slow setting this to on, on my Windows 7 PC.

Code: Select all

q:: ;set high contrast on
vFlags := 0x1 ;on
;vFlags := 0x0 ;off
vSize := A_PtrSize=8?16:12
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
;HCF_HIGHCONTRASTON := 0x1
NumPut(vFlags, &HIGHCONTRAST, 4, "UInt") ;dwFlags
;SPI_SETHIGHCONTRAST := 0x43
DllCall("user32\SystemParametersInfo", UInt,0x43, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
return
Link:
See if High Contrast Theme is On -- Help with DllCall("SystemParametersInfo") - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38972
Thanks, that works perfectly fine on Windows 10, no additional delays compared to manually toggling to high contrast mode using Alt+Shift+PrtScn
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Turn On high contrast mode with autohotkey

11 Dec 2017, 06:41

- Warning: I've written some code for on/off/toggle, however, I had slightly curious results, ending up with Explorer looking part high contrast/part normal. It might have been that the system went funny when I tried putting high contrast on, when it already was on, or something else. For this reason perhaps it's better to get the state, before you try to set the state. Anyhow, setting the theme in Control Panel, puts everything back to normal, or, more or less back to normal.
- Waiting a minute each time you change something, or wanting to restart the PC, to try tests from scratch, is not got great when you want to do a quick test.

Code: Select all

return

;w:: ;set high contrast on
;e:: ;set high contrast off
if InStr(A_ThisHotkey, "w")
	vFlags := 0x1 ;on
if InStr(A_ThisHotkey, "e")
	vFlags := 0x0 ;off
vSize := A_PtrSize=8?16:12
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
;HCF_HIGHCONTRASTON := 0x1
NumPut(vFlags, &HIGHCONTRAST, 4, "UInt") ;dwFlags
;SPI_SETHIGHCONTRAST := 0x43
DllCall("user32\SystemParametersInfo", UInt,0x43, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
return

;==================================================

;q:: ;toggle high contrast
vSize := A_PtrSize=8?16:12
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
;SPI_GETHIGHCONTRAST := 0x42
DllCall("user32\SystemParametersInfo", UInt,0x42, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
vFlags := NumGet(&HIGHCONTRAST, 4, "UInt") ;dwFlags
;JEE_Progress(vFlags, 1000)
if (vFlags & 1) ;HCF_HIGHCONTRASTON := 0x1
	vFlags -= 1
else
	vFlags += 1
;JEE_Progress(vFlags, 1000)
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
NumPut(vFlags, &HIGHCONTRAST, 4, "UInt") ;dwFlags
;SPI_SETHIGHCONTRAST := 0x43
DllCall("user32\SystemParametersInfo", UInt,0x43, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
3be
Posts: 5
Joined: 04 Dec 2022, 17:48

Re: Turn On high contrast mode with autohotkey

11 Dec 2022, 05:00

jeeswg wrote:
11 Dec 2017, 06:41
I've written some code for on/off/toggle
Thank you so much for this code! It works great! I haven't noticed any side effects with it yet.

By the way, toggling the high contrast theme, either by LShift+LAlt+PrtSc or by your code, takes just a few seconds on my computer with Win11.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 215 guests