【问题标题】:The name 'Helper' does not exist in the current context当前上下文中不存在名称“Helper”
【发布时间】:2015-11-04 08:37:03
【问题描述】:

在我的 C# 应用程序中,我使用 MessageFilter 作为全局键挂钩 as suggested by T Perquin.

这是我当前的代码:

 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;
    }
}

当我尝试编译和运行(以确保语法正确)时,我收到以下错误:
The name 'Helper' does not exist in the current context

“Helper”到底是什么?如何解决此错误?

【问题讨论】:

  • Helper 似乎是一个命名空间,其中定义了某些 Windows 消息的常量。使用这样一个通用名称,它不太可能成为标准模块 - 您必须创建自己的,或者只需在本地声明 WM_KEYDOWN,如果这就是您所需要的。
  • @500-InternalServerError 我想使用全局挂钩,以便我的应用程序在最小化时可以使用快捷方式。我将如何将此代码(如果可能的话)用于全局挂钩?

标签: c# compiler-errors syntax-error


【解决方案1】:

看起来Helper 是一个包含静态或常量变量的类,如Windows 消息WM_KEYDOWN。由于您只使用它,因此您可以将其添加到您的文件中。

const int WM_KEYDOWN = 0x100;

这是另一个Keyboard Input Notifications,以备不时之需。

【讨论】:

  • 非常感谢!这对我很有用。一旦选项可用,我将接受这个答案。 :)
猜你喜欢
  • 2013-10-02
  • 2014-04-22
  • 2017-06-17
  • 2015-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-18
相关资源
最近更新 更多