I want to capture key combinations like ALT+CTRL+INSERT
using preTranslateMessage()
in C++ as shown in below code. I could not get what I am expecting. I tried doing logical code changes.
It doesnt seems to be the best solution.Also,using Keyboard Accelerators may solve my problem.But I could not exactly figure out how to do process.
Please anyone suggest me some possible solution..
BOOL BMWView::PreTranslateMessage(MSG* pMsg)
{
//static int k_ctrlPressed,k_altPressed,k_insertPressed = 0;
static int keylog_var = 0;
if (pMsg->message == WM_KEYUP )
{
switch (pMsg->wParam)
{
case VK_CONTROL: if(keylog_var==0) keylog_var = 1; else keylog_var = 0;
break;
case VK_MENU: if(keylog_var==1) keylog_var = 2; else keylog_var = 0;
break;
case VK_INSERT: if(keylog_var==2) keylog_var = 3; else keylog_var = 0;
break;
default: keylog_var = 0;
break;
}
//Switch case is replaced with below if statement
if(keylog_var == 3)
{
keylog_var = 0;
// Set mode
CWnd *pWnd = (CWnd *)this;
pWnd->PostMessage(ID_ENTRY, 0L, 0L);
}
}
return BView::PreTranslateMessage(pMsg);
Simple. Capture a ALT+CTRL+INSERT
with GetKeyState
and test pMsg
for a VK_INSERT
.
BOOL CTestView::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
BOOL bCtrl=::GetKeyState(VK_CONTROL)&0x8000;
BOOL bShift=::GetKeyState(VK_SHIFT)&0x8000;
BOOL bAlt=::GetKeyState(VK_MENU)&0x8000;
switch(pMsg->wParam)
{
case VK_INSERT :
if( bCtrl && bAlt )
{
MessageBox(" Ctrl+Alt+INSERT ", " ",MB_OK);
}
break;
}
}
return CView::PreTranslateMessage(pMsg);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.