-
Notifications
You must be signed in to change notification settings - Fork 3
/
MediaKeys.c
114 lines (55 loc) · 1.8 KB
/
MediaKeys.c
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
#include <jni.h>
#include <stdio.h>
#include "MediaKeys.h"
#define WINVER 0x0500
#include <windows.h>
//Source used for virtual key press code: https://stackoverflow.com/a/2969148/11039508
void pressKey(WORD key) {
KEYBDINPUT kbi;
//specific keycode
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));
return;
}
//hits the volume mute/unmute key
JNIEXPORT void JNICALL Java_commands_MediaKeys_volumeMute (JNIEnv *env, jobject thisObj) {
pressKey(VK_VOLUME_MUTE);
return;
}
//hits the volume down key
JNIEXPORT void JNICALL Java_commands_MediaKeys_volumeDown (JNIEnv *env, jobject thisObj) {
pressKey(VK_VOLUME_DOWN);
return;
}
//hits the volume up key
JNIEXPORT void JNICALL Java_commands_MediaKeys_volumeUp (JNIEnv *env, jobject thisObj) {
pressKey(VK_VOLUME_UP);
return;
}
//hits the previous track key
JNIEXPORT void JNICALL Java_commands_MediaKeys_songPrevious (JNIEnv *env, jobject thisObj) {
pressKey(VK_MEDIA_PREV_TRACK);
return;
}
//hits the next track key
JNIEXPORT void JNICALL Java_commands_MediaKeys_songNext (JNIEnv *env, jobject thisObj) {
pressKey(VK_MEDIA_NEXT_TRACK);
return;
}
//hits the play/pause key
JNIEXPORT void JNICALL Java_commands_MediaKeys_songPlayPause (JNIEnv *env, jobject thisObj) {
pressKey(VK_MEDIA_PLAY_PAUSE);
return;
}
//hits the media stop key
JNIEXPORT void JNICALL Java_commands_MediaKeys_mediaStop (JNIEnv *env, jobject thisObj) {
pressKey(VK_MEDIA_STOP);
return;
}