-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerManagementToggle.py
More file actions
118 lines (103 loc) · 4.68 KB
/
Copy pathPowerManagementToggle.py
File metadata and controls
118 lines (103 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import pyautogui
import time
import keyboard
import win32api, win32con
import pickle
#This program was written in a few hours, its purpose is to set the computer's power usage.
# Disclaimer: This is an awful way to do it, even the cmds, a better way would be NViAPI but I dont want to use it
## 1200 150 , 1220 300 # To open control panel
# Update: 18/12/2021, Made it more consistent so it requires no human intervention, optimized a little more
#Update : 5/2/2022, Made it check for icons repeatedly, fixed crashing
#Update 6/2/2022, added pickling to remember the current power setting
## 776 419, 240 240 240 To scroll down
## 750 419 To click the menu
## 556 431 , 120 185 4 To Check if menu is opened
## Optimal : X same, 430
## Adaptive(Balanced): , 450
## Performance: , 470
ISenabled = True
current_step = 1 ##using this to make it loop if current step is not complete, this prevents common crashing, steps are: 1: Right click on desktop 2: find Nvidia Control Panel 3: click on Nvidia Control Panel
## 4: find scroll wheel 5: click scroll wheel to get to performace settings 6: find performace settings 7: click performance settings 8: choose correct performance setting 9: press the upper right corner to close 10: press enter to apply
def FindPowerSettings(x):
global current_step
while(current_step != 10 or keyboard.is_pressed('q') == False):
try:
Found = False
while(Found == False):
if pyautogui.pixel(776,419)[0] == 240 and pyautogui.pixel(776,419)[1] == 240 and pyautogui.pixel(776,419)[2] == 240:
Found = True
ClickOnPosition(776,419)
time.sleep(0.1)
ClickOnPosition(750,419)
try:
Found2 = False
while(Found2 == False):
if (pyautogui.locateOnScreen('OpenSetting.png', confidence = 0.85)):
Found2 = True
if(x == 1): ClickOnPosition(750, 430)
elif (x == 2): ClickOnPosition(750, 450)
elif (x==3): ClickOnPosition(750, 470)
time.sleep(1)
ClickOnPosition(1919, 0)
time.sleep(1)
keyboard.press_and_release("enter")
else: time.sleep(0.01)
except:
pass
else: time.sleep(0.001)
except:
pass
def PowerSetting(x):
OpenCtrlPanel()
FindPowerSettings(x)
def ClickOnPosition(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.001)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
def OpenCtrlPanel():
openpanel = False
foundpanel = False
while(openpanel == False):
win32api.SetCursorPos((1200,150))
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,0,0)
time.sleep(0.5)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,0,0)
time.sleep(0.25)
openpanel = True
while(foundpanel ==False):
PanelLocation = pyautogui.locateOnScreen('CtrlPnl.png', confidence = 0.85)
if (PanelLocation[1] != 0):
win32api.SetCursorPos((PanelLocation[0],PanelLocation[1]))
time.sleep(0.5)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(0.011)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
foundpanel = True
while (ISenabled == True):
CurrentState = "Unknown"
filename = 'CurrentState.pk'
with open(filename,'rb') as fi:
CurrentState = pickle.load(fi)
print("Current Power State is : " + CurrentState)
e = input("Type s for Saving, b for Balanced, p for Performance, N to cancel: ")
if(e == 's' or e == 'S'):
CurrentState = "Saving"
with open(filename, 'wb') as fi:
pickle.dump(CurrentState,fi)
os.startfile('PowerSaver.cmd')
PowerSetting(1)
elif (e== 'b' or e == 'B'):
CurrentState = "Balanced"
with open(filename, 'wb') as fi:
pickle.dump(CurrentState,fi)
os.startfile('Balanced.cmd')
PowerSetting(2)
elif (e=='p' or e == 'P'):
CurrentState = "Performance"
with open(filename, 'wb') as fi:
pickle.dump(CurrentState,fi)
os.startfile('Performance.cmd')
PowerSetting(3)
elif (e=='n' or e == 'N'): On = False