0

In my C# application, I am using a MessageFilter for a global key hook as suggested by T Perquin.

This is my current code:

 class KeyboardMessageFilter : IMessageFilter
{
    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == ((int)Helper.WindowsMessages.WM_KEYDOWN))
        {
            switch ((int)m.WParam)
            {
                case (int)Keys.Escape:
                    // Do Something
                    return true;
                case (int)Keys.Right:
                    // Do Something
                    return true;
                case (int)Keys.Left:
                    // Do Something
                    return true;
            }
        }

        return false;
    }
}

When I try to compile and run (to make sure the syntax's are correct), I get this error:
The name 'Helper' does not exist in the current context.

What exactly is 'Helper' and how do I fix this error?

Community
  • 1
  • 1
Question Asker
  • 199
  • 2
  • 18
  • `Helper` appears to be a namespace where constants for certain Windows messages are defined. With such a generic name it is unlikely to be a standard module - you will have to create your own, or just declare WM_KEYDOWN locally, if that's all you need. – 500 - Internal Server Error Aug 11 '15 at 22:54
  • @500-InternalServerError I would like to use a global hook so that my application can use shortcuts when minimized. How would I go about using this code (If it's even possible) for a global hook? – Question Asker Aug 11 '15 at 22:55

1 Answers1

4

It looks like Helper is a class that contains static or constant variables like the Windows Message WM_KEYDOWN. Since you are only using that you can add it in your file.

const int WM_KEYDOWN = 0x100;

Here are the other Keyboard Input Notifications, in case you need it.

evanb
  • 3,061
  • 20
  • 32