-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass1.cs
92 lines (79 loc) · 2.94 KB
/
Class1.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Wox.Plugin;
using System.Windows.Interop;
using System.Windows.Forms;
namespace Wox.Plugin.Media
{
public class Plugin : IPlugin
{
[DllImport("User32.dll")]
public static extern void keybd_event(uint bVk, uint bScan, uint dwFlags, uint dwExtraInfo);
public void Init(PluginInitContext context)
{
}
public List<Result> Query(Query query)
{
var queryString = query.Search.ToLower();
List<Result> results = new List<Result>();
var icon = "image.png";
Dictionary<string, Result> QueryResults = new Dictionary<string, Result>
{
{"pa", Result("Play/Pause", "Play/Pause the current track", icon, Action("pause"))},
{"pl", Result("Play/Pause", "Play/Pause the current track", icon, Action("pause"))},
{"ne", Result("Next", "Skip the current track", icon, Action("next"))},
{"pr", Result("Previous", "Go to the last track", icon, Action("previous"))},
{"mu", Result("Mute/Unmute", "Toggle mute", icon, Action("mute"))},
{"sk", Result("Skip", "Skip the current track", icon, Action("next"))}
};
foreach (var x in QueryResults)
{
if (queryString.StartsWith(x.Key))
{
results.Add(x.Value);
}
}
return results;
}
private static Result Result(String title, String subtitle, String icon, Func<ActionContext, bool> action)
{
return new Result()
{
Title = title,
SubTitle = subtitle,
IcoPath = icon,
Action = action
};
}
// The Action method is called after the user selects the item
private static Func<ActionContext, bool> Action(String text)
{
return e =>
{
switch (text)
{
case ("pause"):
keybd_event(0xB3, 0, 0x0001 | 0, 0);
break;
case ("next"):
keybd_event(0xB0, 0, 0x0001 | 0, 0);
break;
case ("previous"):
keybd_event(0xB1, 0, 0x0001 | 0, 0);
break;
case ("mute"):
keybd_event(0xAD, 0, 0x0001 | 0, 0);
break;
default:
break;
}
// return false to tell Wox don't hide query window, otherwise Wox will hide it automatically
return false;
};
}
}
}