Skip to content

Instantly share code, notes, and snippets.

@kaecy
Created October 29, 2021 00:09
Show Gist options
  • Save kaecy/7dff9e5909a6d2bfee91025ab693b145 to your computer and use it in GitHub Desktop.
Save kaecy/7dff9e5909a6d2bfee91025ab693b145 to your computer and use it in GitHub Desktop.
lame foobar2000 remote controller.
#include "stdio.h"
#include "windows.h"
void sendContrlKey(int vKeyCode) {
INPUT inputs[4];
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_CONTROL;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = vKeyCode;
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = VK_CONTROL;
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = vKeyCode;
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(4, inputs, sizeof(INPUT));
}
void sendSingleKey(int vKeyCode) {
INPUT inputs[2];
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = vKeyCode;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = vKeyCode;
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(2, inputs, sizeof(INPUT));
}
void printSong() {
char title[512];
HWND playerWindow;
playerWindow = FindWindow("{97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}", 0);
GetWindowText(playerWindow, title, 512);
printf("%s\n", title);
}
void playSong() {
sendSingleKey(VK_MEDIA_PLAY_PAUSE);
Sleep(500);
printSong();
}
void nextSong() {
sendSingleKey(VK_MEDIA_NEXT_TRACK);
Sleep(500);
printSong();
}
void prevSong() {
sendSingleKey(VK_MEDIA_PREV_TRACK);
Sleep(500);
printSong();
}
int main(int argc, char * argv[]) {
if (argc > 1) {
if (strcmp("play", argv[1]) == 0) {
playSong();
}
else if (strcmp("next", argv[1]) == 0) {
nextSong();
}
else if (strcmp("prev", argv[1]) == 0) {
prevSong();
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment