-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultimediacommand.cpp
More file actions
80 lines (65 loc) · 1.52 KB
/
multimediacommand.cpp
File metadata and controls
80 lines (65 loc) · 1.52 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
#include "multimediacommand.h"
#include "windows.h"
MultimediaCommand::MultimediaCommand(QObject *parent) : ICommand(parent)
{
}
QString MultimediaCommand::GetCommandId()
{
return QString("multimediakey");
}
void MultimediaCommand::ProcessCommand(QJsonObject* command)
{
QString multimediaKey;
/* Check if json contains the needed key */
if (!command->contains("multimediakey"))
{
return;
}
multimediaKey = (*command)["multimediakey"].toString();
if (multimediaKey == "previoustrack")
{
ProcessKey(VK_MEDIA_PREV_TRACK);
}
else if (multimediaKey == "playpause")
{
ProcessKey(VK_MEDIA_PLAY_PAUSE);
}
else if (multimediaKey == "nexttrack")
{
ProcessKey(VK_MEDIA_NEXT_TRACK);
}
else if (multimediaKey == "stop")
{
ProcessKey(VK_MEDIA_STOP);
}
else if (multimediaKey == "mute")
{
ProcessKey(VK_VOLUME_MUTE);
}
else if (multimediaKey == "increasevolume")
{
ProcessKey(VK_VOLUME_UP);
}
else if (multimediaKey == "decreasevolume")
{
ProcessKey(VK_VOLUME_DOWN);
}
else
{
return;
}
return;
}
void MultimediaCommand::ProcessKey(uint16_t mediaKey)
{
INPUT input;
input.type= INPUT_KEYBOARD;
input.ki.wScan = 0;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
input.ki.dwFlags = 0;
input.ki.wVk = mediaKey;
SendInput(1,&input, sizeof(INPUT));
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1,&input, sizeof(INPUT));
}