forked from rainmeter/rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeasureMediaKey.cpp
71 lines (64 loc) · 1.56 KB
/
MeasureMediaKey.cpp
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
/* Copyright (C) 2015 Rainmeter Project Developers
*
* This Source Code Form is subject to the terms of the GNU General Public
* License; either version 2 of the License, or (at your option) any later
* version. If a copy of the GPL was not distributed with this file, You can
* obtain one at <https://www.gnu.org/licenses/gpl-2.0.html>. */
#include "StdAfx.h"
#include "MeasureMediaKey.h"
#include "Logger.h"
MeasureMediaKey::MeasureMediaKey(Skin* skin, const WCHAR* name) : Measure(skin, name)
{
}
MeasureMediaKey::~MeasureMediaKey()
{
}
void SendKey(WORD key)
{
KEYBDINPUT kbi;
kbi.wVk = key;
kbi.wScan = 0;
kbi.dwFlags = 0;
kbi.time = 0;
kbi.dwExtraInfo = (ULONG_PTR)GetMessageExtraInfo();
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki = kbi;
SendInput(1, &input, sizeof(INPUT));
}
void MeasureMediaKey::Command(const std::wstring& command)
{
const WCHAR* args = command.c_str();
if (_wcsicmp(args, L"NextTrack") == 0)
{
SendKey(VK_MEDIA_NEXT_TRACK);
}
else if (_wcsicmp(args, L"PrevTrack") == 0)
{
SendKey(VK_MEDIA_PREV_TRACK);
}
else if (_wcsicmp(args, L"Stop") == 0)
{
SendKey(VK_MEDIA_STOP);
}
else if (_wcsicmp(args, L"PlayPause") == 0)
{
SendKey(VK_MEDIA_PLAY_PAUSE);
}
else if (_wcsicmp(args, L"VolumeMute") == 0)
{
SendKey(VK_VOLUME_MUTE);
}
else if (_wcsicmp(args, L"VolumeDown") == 0)
{
SendKey(VK_VOLUME_DOWN);
}
else if (_wcsicmp(args, L"VolumeUp") == 0)
{
SendKey(VK_VOLUME_UP);
}
else
{
LogErrorF(this, L"Unknown command: %s", args);
}
}