Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Ctrl - Forward Slash in WinForm app

Below is the code for Ctrl + F (from another SO post). But how do you detect a Ctrl + ForwardSlash? or Ctrl + / (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);
    }
like image 903
BuddyJoe Avatar asked Sep 04 '09 18:09

BuddyJoe


1 Answers

Divide should work fine.

For Ctrl + \:

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

For Ctrl + /:

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

For some reason (not sure why), when you trap Ctrl + 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.

like image 144
Reed Copsey Avatar answered Sep 21 '22 02:09

Reed Copsey