-
Notifications
You must be signed in to change notification settings - Fork 1
/
modStreamDeck.vb
139 lines (131 loc) · 6.27 KB
/
modStreamDeck.vb
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Imports OpenMacroBoard.SDK
Imports StreamDeckSharp
Module modStreamDeck
Private ActiveStreamDeck As IStreamDeckBoard
Private HoldTimer As New Stopwatch
Private KeyCount As Integer
Function Disable() As String
Unload()
My.Settings.StreamDeck_Enable = False
My.Application.Log.WriteEntry("Stream Deck module is disabled")
Return "Stream Deck module disabled"
End Function
Function Enable() As String
My.Settings.StreamDeck_Enable = True
My.Application.Log.WriteEntry("Stream Deck module is enabled")
Load()
Return "Stream Deck module enabled"
End Function
Function Load() As String
If My.Settings.StreamDeck_Enable = True Then
My.Application.Log.WriteEntry("Loading Stream Deck module")
Try
ActiveStreamDeck = StreamDeck.OpenDevice()
If ActiveStreamDeck.IsConnected = True Then
KeyCount = ActiveStreamDeck.Keys.Count
If KeyCount = 15 Then
My.Application.Log.WriteEntry("Standard Stream Deck detected")
ElseIf KeyCount = 6 Then
My.Application.Log.WriteEntry("Stream Deck Mini detected")
End If
AddHandler ActiveStreamDeck.KeyStateChanged, AddressOf StreamDeckKeyStateChanged
SetStreamDeckKeys()
Return "Stream Deck module loaded"
Else
Return "Stream Deck not loaded"
End If
Catch StreamDeckExcep As StreamDeckSharp.Exceptions.StreamDeckException
My.Application.Log.WriteException(StreamDeckExcep)
If My.Settings.Global_CarMode = True Then
modSpeech.Say("Stream Deck not found")
End If
Return "Stream Deck not found"
End Try
Else
My.Application.Log.WriteEntry("Stream Deck module is disabled, module not loaded")
Return "Stream Deck module is disabled, module not loaded"
End If
End Function
Function Unload() As String
My.Application.Log.WriteEntry("Unloading Stream Deck module")
If IsNothing(ActiveStreamDeck) = False AndAlso ActiveStreamDeck.IsConnected = True Then
ActiveStreamDeck.ShowLogo()
ActiveStreamDeck.Dispose()
End If
Return "Stream Deck module unloaded"
End Function
Private Sub SetStreamDeckKeys()
If KeyCount = 15 Then
Dim iconLock = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Lock.png")
ActiveStreamDeck.SetKeyBitmap(0, iconLock)
Dim iconMusic = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Music.png")
ActiveStreamDeck.SetKeyBitmap(1, iconMusic)
Dim iconUrgent = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Urgent.png")
ActiveStreamDeck.SetKeyBitmap(4, iconUrgent)
Dim iconPrevious = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Previous.png")
ActiveStreamDeck.SetKeyBitmap(5, iconPrevious)
Dim iconPause = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Pause.png")
ActiveStreamDeck.SetKeyBitmap(6, iconPause)
Dim iconPlay = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Play.png")
ActiveStreamDeck.SetKeyBitmap(7, iconPlay)
Dim iconNext = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Next.png")
ActiveStreamDeck.SetKeyBitmap(8, iconNext)
Dim iconRestart = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Restart.png")
ActiveStreamDeck.SetKeyBitmap(9, iconRestart)
Dim iconSquare1 = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Square1.png")
ActiveStreamDeck.SetKeyBitmap(10, iconSquare1)
Dim iconSquare2 = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Square2.png")
ActiveStreamDeck.SetKeyBitmap(11, iconSquare2)
Dim iconSquare3 = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Square3.png")
ActiveStreamDeck.SetKeyBitmap(12, iconSquare3)
Dim iconSquare4 = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Square4.png")
ActiveStreamDeck.SetKeyBitmap(13, iconSquare4)
Dim iconPower = KeyBitmap.Create.FromFile("C:\HAC\assets\modStreamDeck\Power.png")
ActiveStreamDeck.SetKeyBitmap(14, iconPower)
Else
My.Application.Log.WriteEntry("Only the 15 key Stream Deck is currently supported", TraceEventType.Warning)
End If
End Sub
Private Sub StreamDeckKeyStateChanged(sender As Object, e As KeyEventArgs)
If e.IsDown = True Then
My.Application.Log.WriteEntry(e.Key.ToString & " pressed")
HoldTimer.Start()
Else
My.Application.Log.WriteEntry(e.Key.ToString & " released")
HoldTimer.Stop()
Select Case e.Key
Case 0
modComputer.LockScreen()
Case 1
modMusic.PlayPlaylist(My.Settings.Music_LastPlaylist)
Case 4
modConverse.Interpret("pursuit mode")
Case 5
modMusic.PlayPrevious()
Case 6
modMusic.PauseMusic()
Case 7
modMusic.ResumeMusic()
Case 8
modMusic.PlayNext()
Case 9
If HoldTimer.ElapsedMilliseconds > 3000 Then
modComputer.RebootHost()
End If
Case 10
modPersons.RunPreset(1, My.Settings.Global_PrimaryUser)
Case 11
modPersons.RunPreset(2, My.Settings.Global_PrimaryUser)
Case 12
modPersons.RunPreset(3, My.Settings.Global_PrimaryUser)
Case 13
modPersons.RunPreset(4, My.Settings.Global_PrimaryUser)
Case 14
If HoldTimer.ElapsedMilliseconds > 3000 Then
modComputer.ShutdownHost()
End If
End Select
HoldTimer.Reset()
End If
End Sub
End Module