控制台方式 ,MSDN实例代码:
#include "stdafx.h"
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
if (RegisterHotKey(
NULL,
1,
MOD_ALT | MOD_NOREPEAT,
0x42)) //0x42 is 'b'
{
_tprintf(_T("Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\n"));
}
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY)
{
_tprintf(_T("WM_HOTKEY received\n"));
}
}
return 0;
}
MFC方式 , 打开对话框,添加消息 : WM_HOTKEY 在OnCreat事件里加入:(添加消息响应 -> WM_CREAT) RegisterHotKey(m_hWnd,1001,MOD_ALT,’ Q’);
LRESULT CdDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
if(wParam == 1001)
{
int nMod = LOWORD(lParam);
int Vk = HIWORD(lParam);
CString str;
str.Format(_T("Mod = %d, Vk = %d"), nMod, Vk);
AfxMessageBox(str);
}
return true;
}
0 条评论