これを行う正しい方法は、おそらくタイプWH_KEYBOARDまたはWH_KEYBOARD_LLフックのWindowsフックを使用して(ただし、WH_GETMESSAGEも機能します)、そこで処理を行うことです。
SetWindowsHookExのドキュメント(http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx )を参照してください。
I haven't tested this - just whipped it up on the fly - but here's a simple example that should do what you want when the 'A' key is pressed.
LRESULT __stdcall CALLBACK LoveProc(int nCode, WPARAM wParam, LPARAM lParam)
{
static int love = 0;
if((nCode == HC_ACTION) &&
(wParam == 'A') && /* the key pressed was 'A' */
(lParam & 0x40000000)) /* trigger when the key is pressed */
{
if(love == 0)
play_romantic_love_song();
/* but don't overdo it because "Too Much Love Will Kill You" */
love = 1;
}
return CallNextHookEx(hOldKeyHook, nCode, wParam, lParam );
}
You may also want to google for "*SetWindowsHookEx WH_KEYBOARD*" as I'm pretty sure there's at least a couple of articles that explain this on CodeProject. I'd include the links, but I'm typing this from my iPhone and it's being... difficult.