截断WM_SYSKEYDOWN难道不行吗?这也不算SDK? 楼主只是要让按键响应某个事件,是吗?为什么不使用注册热键呢?首先要在OnCreate中添加热键注册行为 // TODO: Add your specialized creation code here if(!RegisterHotKey(this->m_hWnd,1001,MOD_ALT,0x0d)) { MessageBox("注册热键Ctrl+N失败!"); return FALSE; } 然后,在消息中进行处理相关的热键 BOOL CMenuContrlAndPower::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_HOTKEY) {
if((int)(pMsg->wParam)==1001) {
AfxMessageBox("Alt+Enter"); }
} return CDialog::PreTranslateMessage(pMsg); }
晕死,同样的代码,为什么上次怎么弄都不行呢换成VK_F1就能断下,换成VK_RETURN就不行。这次试了试,居然又行了太诡异了 case WM_SYSKEYDOWN: if( wParam == VK_RETURN ) int a = 0; // 下断点 break;不管怎么说,谢谢了!
【Windows 程序设计】【下载地址】http://blog.csdn.net/zaodt/archive/2007/11/25/1901332.aspx
WM_SYSKEYDOWN 可以获取 Alt + A,但同样无法获取 Alt + Enter,请亲自测试,谢谢!
{
if( pMsg->message == WM_SYSKEYDOWN )
{
bool bReturn = (GetKeyState(VK_RETURN)&0x80000000) != 0; if (bReturn)
{
TRACE(_T("ALT + Return\n"));
}
}
return CDialog::PreTranslateMessage(pMsg);
}
我需要用SDK编程,因此没有 PreTranslateMessage 函数。
{
switch (message)
{
case WM_SYSKEYDOWN:
...
case ...
...}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
在每个周期都检测所有按键的输入状态,如果DIK_ALT 和DIK_ENTR同时按下就OK啦。
#pragma comment(lib,"dinput8.lib")LPDIRECTINPUT8 lpdi;
LPDIRECTINPUTDEVICE8 lpdikey;UCHAR keybord_statue[256];
UCHAR TempKey1[256];
UCHAR TempKey2[256];/**初始化DINPUT按口**/
BOOL Init_KeyDevice(HWND hWnd,HINSTANCE MI_hInstance)
{
if(FAILED(DirectInput8Create(MI_hInstance,DIRECTINPUT_VERSION,IID_IDirectInput8,(void * *)&lpdi,NULL)))return FALSE;
if(FAILED(lpdi->CreateDevice(GUID_SysKeyboard,&lpdikey,NULL)))return FALSE;
if(FAILED(lpdikey->SetCooperativeLevel(hWnd,DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))return FALSE;
if(FAILED(lpdikey->SetDataFormat(&c_dfDIKeyboard)))return FALSE;
if(FAILED(lpdikey->Acquire()))return FALSE;
return TURN;
}/**获取按键状态**/
void GetKey(void)
{
WORD Index;
if(lpdikey==NULL)return;
lpdikey->GetDeviceState(256,(LPVOID)keybord_statue);
for(Index=0;Index<256;Index++)
{
TempKey2[Index]=TempKey1[Index];
TempKey1[Index]=keybord_statue[Index];
}
}/**判断某个键的状态**/
WORD _GetAsyncKeyState(UCHAR KeyName)
{
if(TempKey2[KeyName]==0)
{
if(TempKey1[KeyName]==0) return 0; //无按键
else return 3; //按瞬
}
else
{
if(TempKey1[KeyName]==0) return 1; //按键弹起瞬间
else return 2; //长按
}
}/**在程序中调用**/
{
Init_KeyDevice(M_hWnd,M_hInstance);
while(1)
{
GetKey();
if(_GetAsyncKeyState(DIK_ATL)==2 && _GetAsyncKeyState(DIK_ENTR)==2)
{
....你要处理的代码....
}
}
}
WM_SYSKEYUP
WM_SYSCHAR
创建一个SDK项目
在WndProc的switch里加入: case WM_SYSKEYDOWN:
{
int vkey = (int)wParam;
if( vkey == VK_RETURN )
{
int a = 0; // 下断点
}
}
break;F5,按Alt-Enter,OK断下
...
while(GetMessgae(&msg,NULL,NULL,NULL))
{
if(PreTranslateMsg())//PreTranslateMsg是你自定义的一个函数;在这里处理你的消息,详见罗云彬的win32汇编
cotinue;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
楼主只是要让按键响应某个事件,是吗?为什么不使用注册热键呢?首先要在OnCreate中添加热键注册行为
// TODO: Add your specialized creation code here
if(!RegisterHotKey(this->m_hWnd,1001,MOD_ALT,0x0d))
{
MessageBox("注册热键Ctrl+N失败!");
return FALSE;
}
然后,在消息中进行处理相关的热键
BOOL CMenuContrlAndPower::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_HOTKEY)
{
if((int)(pMsg->wParam)==1001)
{
AfxMessageBox("Alt+Enter");
}
}
return CDialog::PreTranslateMessage(pMsg);
}
晕死,同样的代码,为什么上次怎么弄都不行呢换成VK_F1就能断下,换成VK_RETURN就不行。这次试了试,居然又行了太诡异了
case WM_SYSKEYDOWN:
if( wParam == VK_RETURN )
int a = 0; // 下断点
break;不管怎么说,谢谢了!