user3161924
user3161924

Reputation: 2327

MFC: Accelerators for Ctrl-Shift don't work?

I have some accelerators configured and if using just the Ctrl key it works fine, but if I make it Shift+Ctrl it doesn't work (doesn't even show as a shortcut in the MFC menus where as the Ctrl version does). The entries I've tried with both upper and lower case letters, doesn't make a difference. This is what the entries in the accelerators look like:

"R",            ID_R1,        VIRTKEY, CONTROL, NOINVERT
"R",            ID_R2,        VIRTKEY, SHIFT, CONTROL, NOINVERT

What am I doing wrong?

Edit: I made the "R" capital above because of the two answer talking about that, but I originally had "R" and only changed to "r" before giving up and asking here. But the "R" doesn't work for Ctrl-Shift-R either, where as the Ctrl-R works fine?

Edit: Using Spy x64 and checking the main window, never get a command sent. If I go to the list view on the right side of a splitter window and press Ctrl-Shift-R in that order, the only thing generated is:

<000041> 00000000002100D6 P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:0 fUp:0
<000042> 00000000002100D6 S LVM_GETNEXTITEM iStart:-1 flags:LVNI_SELECTED
<000043> 00000000002100D6 R LVM_GETNEXTITEM iIndex:-1
<000044> 00000000002100D6 P WM_KEYDOWN nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:0 fUp:0
<000045> 00000000002100D6 S LVM_GETNEXTITEM iStart:-1 flags:LVNI_SELECTED
<000046> 00000000002100D6 R LVM_GETNEXTITEM iIndex:-1
<000047> 00000000002100D6 P WM_KEYUP nVirtKey:'R' cRepeat:1 ScanCode:13 fExtended:0 fAltDown:0 fRepeat:0 fUp:1
<000048> 00000000002100D6 S LVM_GETNEXTITEM iStart:-1 flags:LVNI_SELECTED
<000049> 00000000002100D6 R LVM_GETNEXTITEM iIndex:-1
<000050> 00000000002100D6 P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:1 ScanCode:2A fExtended:0 fAltDown:0 fRepeat:1 fUp:1
<000051> 00000000002100D6 S LVM_GETNEXTITEM iStart:-1 flags:LVNI_SELECTED
<000052> 00000000002100D6 R LVM_GETNEXTITEM iIndex:-1
<000053> 00000000002100D6 P WM_KEYUP nVirtKey:VK_CONTROL cRepeat:1 ScanCode:1D fExtended:0 fAltDown:0 fRepeat:1 fUp:1

Edit:

Even more data, I placed a conditional breakpoint in thrdcore.cpp at line 178 where the message loop is (the line is if (pState->m_msgCur.message != WM_KICKIDLE && !AfxPreTranslateMessage(&(pState->m_msgCur)))). The break point is: pState->m_msgCur.message==0x0100 && pState->m_msgCur.wParam==0x52 (WM_KEYDOWN for R). When pressing R or Ctrl-R the breakpoint hits, when pressing Ctrl-Shift-R the breakpoint doesn't occur. Above spy trace there is never a WM_KEYDOWN for the R, only an up?

Edit:

Now really getting weird. I decided to go in to the keyboard settings for VS2017 and see if something assigned to Ctrl-Shift-R, I press it and nothing happens, I try any other letter like Ctrl-Shift-T and it works fine. Could it by my keyboard? Or something deeper in Win10 x64 that is eating a WM_KEYDOWN for R when Ctrl-Shift is pressed?

Thanks.

Upvotes: 0

Views: 337

Answers (2)

Zeus
Zeus

Reputation: 3890

The reason why the title names of accelerator keys and menu items are not updated is that the registry information is not updated.

There are two solutions for your reference:

First, you can manually delete the information in the registry.You can enter the registry area:

HKEY_CURRENT_USER\SOFTWARE\Local AppWizard-Generated Applications

Then delete the registry information of your current application name, and it will work normally after recompiling the program.

In the second method, you can clear the registry information by adding the CleanState() function to the ExitInstance() function. After restarting the program, the key information and menu bar information of the current program will be updated.

You can refer to:

int CMFCApplication1App::ExitInstance()
{
    //TODO: handle additional resources you may have added
    AfxOleTerm(FALSE);
    this->CleanState();
    return CWinAppEx::ExitInstance();
}

And both solutions worked for me.

Upvotes: 1

Vlad Feinstein
Vlad Feinstein

Reputation: 11321

You should use upper-case characters in the accelerator table:

"R",            ID_R2,        VIRTKEY, SHIFT, CONTROL, NOINVERT

To show the shortcut keys on the menu, you have to modify the menu item itself, like change

MENUITEM "&New\tCtrl+N",                ID_FILE_NEW

to

MENUITEM "&New\tCtrl+Shift+N",          ID_FILE_NEW

Upvotes: 0

Related Questions