-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.py
123 lines (104 loc) · 3 KB
/
sound.py
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
119
120
121
122
123
from keyboard_controller import Keyboard
class Sound:
__current_volume = None
@staticmethod
def current_volume():
"""
Current volume getter
:return: int
"""
if Sound.__current_volume is None:
return 0
else:
return Sound.__current_volume
@staticmethod
def __set_current_volume(volume):
"""
Current volumne setter
prevents numbers higher than 100 and numbers lower than 0
:return: void
"""
if volume > 100:
Sound.__current_volume = 100
elif volume < 0:
Sound.__current_volume = 0
else:
Sound.__current_volume = volume
# The sound is not muted by default, better tracking should be made
__is_muted = False
@staticmethod
def is_muted():
"""
Is muted getter
:return: boolean
"""
return Sound.__is_muted
@staticmethod
def __track():
"""
Start tracking the sound and mute settings
:return: void
"""
if Sound.__current_volume == None:
Sound.__current_volume = 0
for i in range(0, 50):
Sound.volume_up()
@staticmethod
def mute():
"""
Mute or un-mute the system sounds
Done by triggering a fake VK_VOLUME_MUTE key event
:return: void
"""
Sound.__track()
Sound.__is_muted = (not Sound.__is_muted)
Keyboard.key(Keyboard.VK_VOLUME_MUTE)
@staticmethod
def volume_up():
"""
Increase system volume
Done by triggering a fake VK_VOLUME_UP key event
:return: void
"""
Sound.__track()
Sound.__set_current_volume(Sound.current_volume() + 2)
Keyboard.key(Keyboard.VK_VOLUME_UP)
@staticmethod
def volume_down():
"""
Decrease system volume
Done by triggering a fake VK_VOLUME_DOWN key event
:return: void
"""
Sound.__track()
Sound.__set_current_volume(Sound.current_volume() - 2)
Keyboard.key(Keyboard.VK_VOLUME_DOWN)
@staticmethod
def volume_set(amount):
"""
Set the volume to a specific volume, limited to even numbers.
This is due to the fact that a VK_VOLUME_UP/VK_VOLUME_DOWN event increases
or decreases the volume by two every single time.
:return: void
"""
Sound.__track()
if Sound.current_volume() > amount:
for i in range(0, int((Sound.current_volume() - amount) / 2)):
Sound.volume_down()
else:
for i in range(0, int((amount - Sound.current_volume()) / 2)):
Sound.volume_up()
@staticmethod
def volume_min():
"""
Set the volume to min (0)
:return: void
"""
Sound.volume_set(0)
@staticmethod
def volume_max():
"""
Set the volume to max (100)
:return: void
"""
Sound.volume_set(100)