-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpotifyHelper.cs
More file actions
69 lines (63 loc) · 1.91 KB
/
SpotifyHelper.cs
File metadata and controls
69 lines (63 loc) · 1.91 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
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Microsoft.Samples.Kinect.DiscreteGestureBasics
{
public static class SpotifyHelper
{
public enum SpotifyAction
{
PlayPause,
Next,
Previous,
VolumeUp,
VolumeDown,
Mute,
Quit
};
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public static void controlSpotify(SpotifyAction sa)
{
BringToForeground("Spotify");
switch (sa)
{
case SpotifyAction.Next:
SendKeys.SendWait("^({RIGHT})");
break;
case SpotifyAction.Previous:
SendKeys.SendWait("^({LEFT})");
break;
case SpotifyAction.VolumeUp:
SendKeys.SendWait("^({UP})");
break;
case SpotifyAction.VolumeDown:
SendKeys.SendWait("^({DOWN})");
break;
case SpotifyAction.PlayPause:
SendKeys.SendWait(" ");
break;
}
}
private static bool BringToForeground(string processName)
{
try
{
var processes = Process.GetProcessesByName(processName);
foreach (var process in processes)
{
ShowWindow(process.MainWindowHandle, 3);
SetForegroundWindow(process.MainWindowHandle);
}
return true;
}
catch (Exception)
{
return false;
}
}
}
}