Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active January 11, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfillion/d86da67035b897345afd7b2ea82f7ff6 to your computer and use it in GitHub Desktop.
Save cfillion/d86da67035b897345afd7b2ea82f7ff6 to your computer and use it in GitHub Desktop.
// Demo REAPER extension to intercept keyboard input
// https://i.imgur.com/xMSrqRr.gif
#include <cstdio>
#include <reaper_plugin.h>
static int (*plugin_register)(const char *name, void *infostruct);
static int HandleKey(MSG *, accelerator_register_t *);
static accelerator_register_t g_accel{HandleKey, true};
extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(
REAPER_PLUGIN_HINSTANCE instance, reaper_plugin_info_t *rec)
{
if(!rec) {
plugin_register("-accelerator", &g_accel);
return 0;
}
if(rec->caller_version != REAPER_PLUGIN_VERSION)
return 0;
(plugin_register = rec->Register)("accelerator", &g_accel);
return 1;
}
int HandleKey(MSG *event, accelerator_register_t *)
{
const char *name;
switch(event->message) {
case WM_KEYUP:
name = "keyup";
break;
case WM_KEYDOWN:
name = "keydown";
break;
default:
name = "???";
break;
};
printf("%s: %lu\n", name, event->wParam);
return 0; // "not our window" (makes REAPER continue processing the event normally)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment