views:

433

answers:

1

Below is the code for Ctrl-F (from another SO post). But how do you detect a Ctrl-ForwardSlash? or Ctrl-Slash (note: divide does not work)

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (1 == 1) //keyData == (Keys.Control | Keys.F))
        {
            MessageBox.Show("What the Ctrl+F?");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
+2  A: 

Divide should work fine.

For Ctrl-BackSlash:

if (keyData == (Keys.Control | Keys.OemPipe) )

For Ctrl-Forward Slash:

if (keyData == (Keys.Control | Keys.OemQuestion) )

For some reason (not sure why), when you trap control + these keys, they're mapping to the "shifted" keymappings.


Edit:

One trick for finding this, or any other key. Set a breakpoint on any line in that method, and look at the keyData value when you press the key you're trying to trap. I recommend doing this without hitting control. You can then use reflector to get all of the specific values for Keys, and find the "key" with the appropriate value.

Reed Copsey
didn't work for me. note: I'm talking about the / above enter or near it. Not on the numeric keypad (if you are on laptop). Any simple way to capture actual key codes in a messagebox and then just rewrite using numeric codes?
tyndall
@Tyndall: I just tested this. My new answer will give you the correct response.
Reed Copsey
On my keyboard, the backslash is above enter.
recursive
@recursive. It is on mine too.
Reed Copsey
sorry I meant / below and to the left of enter on the ? key. Wonder, why the / maps to shifted with the Ctrl pressed. Seems like a bug. I play around with this more. May just have the users use F12, if I can't make this reliable across my corp's desktops and laptops (7 or 8 models)
tyndall