Skip to content

Commit 13d1c81

Browse files
committed
Script upload
1 parent 81464a0 commit 13d1c81

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed

redshiftKeys.ahk

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
2+
#SingleInstance ; Only allows one instance of the script to run.
3+
#Warn ; Enable warnings to assist with detecting common errors.
4+
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
5+
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
6+
7+
8+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9+
;;;;;; REDSHIFT KEYS by ImOnMars ;;;;;;
10+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11+
; Created so that you can manually modify screen color temperature using hotkeys on Windows
12+
;
13+
; To make this run automatically when your PC starts, put it (or a shortcut to it) in the Startup folder (For Windows 10: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp)
14+
;
15+
; Requirements:
16+
; - AutoHotkey
17+
; - Redshift
18+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19+
20+
21+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22+
;;;;;; CONFIG OPTIONS ;;;;;;
23+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24+
25+
; Redshift Settings
26+
REDSHIFT_PATH = redshift ; The path where redshift is, if redshift is in your path environment variable, then you can leave as is
27+
28+
; Options File
29+
SAVE_OPTIONS := true ; Whether or not to save options to a file after script restart or PC reboot
30+
OPTIONS_PATH = C:\redshiftKeysOptions.ini ; Path of where to save options if SAVE_OPTIONS is true
31+
32+
; Shift Values
33+
STARTING_SHIFT = 5500 ; Shift to set when starting the script (on boot or restart) and SAVE_OPTIONS is false or the ini file isn't set
34+
DEFAULT_SHIFT = 6500 ; Default Windows color temperature when shift is disabled
35+
MIN_SHIFT = 3500 ; Minimum shift that the script will decrement to
36+
MAX_SHIFT = 7500 ; Maximum shift that the script will increment to
37+
SHIFT_INCREMENT = 250 ; Amount that the shift will increment/decrement by
38+
39+
; Hotkeys, see here for key combinations: https://autohotkey.com/docs/Hotkeys.htm
40+
TOGGLE_SHIFT_HOTKEY = <#y ; Default: (Left Windows Key + y)
41+
INCREASE_SHIFT_HOTKEY = <#[ ; Default: (Left Windows Key + [)
42+
DECREASE_SHIFT_HOTKEY = <#] ; Default: (Left Windows Key + ])
43+
44+
; General Options
45+
START_ON_RUN := true ; Whether to start with shift or not when starting the script (on boot or restart) and SAVE_OPTIONS is false or the ini file isn't set
46+
SHOW_SHIFT_GUI := true ; Whether the current shift GUI should be shown when pressing hotkeys
47+
SHIFT_AMOUNT_GUI_RELATIVE := false ; Whether the current shift GUI should be relative to the DEFAULT_SHIFT (ex: if DEFAULT_SHIFT = 6500 and the current shift is 5500, it will display -1000)
48+
49+
50+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51+
;;;;;; INITIAL RUN ;;;;;;
52+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53+
54+
; Defaults
55+
isEnabled := START_ON_RUN
56+
curShift := STARTING_SHIFT
57+
58+
; If necessary, read or write all of the options
59+
if (SAVE_OPTIONS)
60+
{
61+
if (FileExist(OPTIONS_PATH))
62+
{
63+
readAllOptionsFromFile()
64+
}
65+
else
66+
{
67+
writeAllOptionsToFile()
68+
}
69+
}
70+
71+
; Set the initial shift values
72+
if (isEnabled)
73+
{
74+
Run, %REDSHIFT_PATH% -O %curShift%,, Hide
75+
shiftAmountBox(curShift, true)
76+
}
77+
else
78+
{
79+
Run, %REDSHIFT_PATH% -x,, Hide
80+
}
81+
82+
83+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84+
;;;;;; HOTKEY BINDINGS ;;;;;;
85+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86+
87+
; Apply the hotkeys set above to their respective actions
88+
Hotkey, %TOGGLE_SHIFT_HOTKEY%, ToggleShift
89+
Hotkey, %INCREASE_SHIFT_HOTKEY%, IncreaseShift
90+
Hotkey, %DECREASE_SHIFT_HOTKEY%, DecreaseShift
91+
return
92+
93+
ToggleShift:
94+
if (isEnabled)
95+
{
96+
Run, %REDSHIFT_PATH% -x,, Hide
97+
isEnabled := false
98+
shiftAmountBox(DEFAULT_SHIFT, true)
99+
}
100+
else
101+
{
102+
Run, %REDSHIFT_PATH% -O %curShift%,, Hide
103+
isEnabled := true
104+
shiftAmountBox(curShift, true)
105+
}
106+
writeOptionToFile("startShifted", isEnabled)
107+
return
108+
109+
IncreaseShift:
110+
if (isEnabled)
111+
{
112+
if ((curShift + SHIFT_INCREMENT) < MAX_SHIFT)
113+
{
114+
curShift += SHIFT_INCREMENT
115+
}
116+
else
117+
{
118+
curShift := MAX_SHIFT
119+
}
120+
Run, %REDSHIFT_PATH% -O %curShift%,, Hide
121+
shiftAmountBox(curShift)
122+
writeOptionToFile("currentShift", curShift)
123+
}
124+
return
125+
126+
DecreaseShift:
127+
if (isEnabled)
128+
{
129+
if ((curShift - SHIFT_INCREMENT) > MIN_SHIFT)
130+
{
131+
curShift -= SHIFT_INCREMENT
132+
}
133+
else
134+
{
135+
curShift := MIN_SHIFT
136+
}
137+
Run, %REDSHIFT_PATH% -O %curShift%,, Hide
138+
shiftAmountBox(curShift)
139+
writeOptionToFile("currentShift", curShift)
140+
}
141+
return
142+
143+
144+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145+
;;;;;; INI FILE MANAGEMENT ;;;;;;
146+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147+
148+
writeOptionToFile(optionName, optionValue)
149+
{
150+
global SAVE_OPTIONS
151+
global OPTIONS_PATH
152+
153+
if (NOT SAVE_OPTIONS)
154+
{
155+
return
156+
}
157+
158+
IniWrite, %optionValue%, %OPTIONS_PATH%, General, %optionName%
159+
}
160+
161+
readOptionFromFile(optionName, ByRef optionValue)
162+
{
163+
global SAVE_OPTIONS
164+
global OPTIONS_PATH
165+
166+
if (NOT SAVE_OPTIONS)
167+
{
168+
return
169+
}
170+
171+
IniRead, optionValue, %OPTIONS_PATH%, General, %optionName%
172+
}
173+
174+
writeAllOptionsToFile()
175+
{
176+
global SAVE_OPTIONS
177+
global curShift
178+
global isEnabled
179+
180+
if (NOT SAVE_OPTIONS)
181+
{
182+
return
183+
}
184+
185+
writeOptionToFile("currentShift", curShift)
186+
writeOptionToFile("startShifted", isEnabled)
187+
}
188+
189+
readAllOptionsFromFile()
190+
{
191+
global SAVE_OPTIONS
192+
global curShift
193+
global isEnabled
194+
195+
if (NOT SAVE_OPTIONS)
196+
{
197+
return
198+
}
199+
200+
readOptionFromFile("currentShift", curShift)
201+
readOptionFromFile("startShifted", isEnabled)
202+
}
203+
204+
205+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206+
;;;;;; GUI ;;;;;;
207+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208+
209+
; Shift Amount GUI
210+
shiftAmountBox(shiftValue, enabledMessage := false)
211+
{
212+
global SHOW_SHIFT_GUI
213+
global SHIFT_AMOUNT_GUI_RELATIVE
214+
global DEFAULT_SHIFT
215+
global isEnabled
216+
217+
if (NOT SHOW_SHIFT_GUI)
218+
{
219+
return
220+
}
221+
222+
IfWinExist, shiftAmountWindow
223+
{
224+
Gui, Destroy
225+
}
226+
227+
if (SHIFT_AMOUNT_GUI_RELATIVE)
228+
{
229+
shiftValue -= DEFAULT_SHIFT
230+
}
231+
232+
Gui, +ToolWindow -Caption +0x400000 +AlwaysOnTop
233+
Gui, Color, FFFFFF,
234+
Gui, Font, s12, Calibri
235+
Gui, Add, Text, x5 y5, Current Shift:
236+
Gui, Font, Bold
237+
Gui, Add, Text, x100 y5, %shiftValue%
238+
if (enabledMessage)
239+
{
240+
Gui, Font, Norm
241+
if (isEnabled)
242+
{
243+
Gui, Add, Text, x140 y5, (Enabled)
244+
}
245+
else
246+
{
247+
Gui, Add, Text, x140 y5, (Disabled)
248+
}
249+
}
250+
SysGet, screenx, 0
251+
SysGet, screeny, 1
252+
xpos:=screenx-275
253+
ypos:=screeny-100
254+
Gui, Show, NoActivate x%xpos% y%ypos% h30 w260, shiftAmountWindow
255+
256+
SetTimer, shiftAmountClose, 2250
257+
}
258+
shiftAmountClose:
259+
SetTimer, shiftAmountClose, Off
260+
Gui, Destroy
261+
return

0 commit comments

Comments
 (0)