forked from garvit-exe/AliceAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonpc_control.py
More file actions
103 lines (79 loc) · 2.85 KB
/
pythonpc_control.py
File metadata and controls
103 lines (79 loc) · 2.85 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
# import pyautogui
import os
import ctypes
import pyautogui
import sys
import time
import screen_brightness_control as sbc
def sanitize_input(text):
"""Sanitize user input to prevent injection attacks."""
if text is None:
return ""
# Allow alphanumeric characters, spaces, and basic punctuation
return ''.join(c for c in str(text) if c.isalnum() or c.isspace() or c in '.,!?-')
# Define constants for volume control
VK_VOLUME_UP = 0xAF
VK_VOLUME_DOWN = 0xAE
# Define constants for brightness control
DISPLAY_BRIGHTNESS = -1 # Use -1 to indicate the primary display
def commands(query):
query = query.lower()
if "volume" in query:
if "increase" in query:
ctypes.windll.user32.keybd_event(VK_VOLUME_UP, 0, 0, 0)
ctypes.windll.user32.keybd_event(VK_VOLUME_UP, 0, 2, 0)
elif "decrease" in query:
ctypes.windll.user32.keybd_event(VK_VOLUME_DOWN, 0, 0, 0)
ctypes.windll.user32.keybd_event(VK_VOLUME_DOWN, 0, 2, 0)
if "brightness" in query:
if "increase" in query:
sbc.set_brightness(100)
print(sbc.get_brightness())
if "slightly" in query:
sbc.set_brightness(70)
print(sbc.get_brightness())
elif "decrease" in query:
sbc.set_brightness(0)
print(sbc.get_brightness())
if "slightly" in query:
sbc.set_brightness(20)
print(sbc.get_brightness())
elif "set brightness to" in query:
query = query.replace("set brightness to ", "")
sbc.set_brightness(query)
if "shutdown" in query:
pyautogui.hotkey('win','x')
time.sleep(1)
pyautogui.press('up',presses=2)
pyautogui.press('enter')
pyautogui.press('up',presses=2)
pyautogui.press('enter')
if "sleep" in query:
pyautogui.hotkey('win','x')
time.sleep(1)
pyautogui.press('up',presses=2)
pyautogui.press('enter')
pyautogui.press('down')
pyautogui.press('enter')
if "restart" in query:
pyautogui.hotkey('win','x')
time.sleep(1)
pyautogui.press('up',presses=2)
pyautogui.press('enter')
pyautogui.press('up')
pyautogui.press('enter')
if "sign out" in query:
pyautogui.hotkey('win','x')
time.sleep(1)
pyautogui.press('up',presses=2)
pyautogui.press('enter',presses=2)
if "open application" in query:
pyautogui.hotkey('win','s')
query=query.replace("open application ","")
# Sanitize input to prevent injection of special characters
time.sleep(1)
pyautogui.write(sanitize_input(query))
pyautogui.press('enter')
if len(sys.argv) > 1:
query = sys.argv[1]
commands(query)