鼠标键挂钩 - 键侦听器未触发

Mouse Key Hook - Key listener not firing

我正在使用 Global MouseKeyHook 来收听鼠标点击和按键操作,同时在 VLC activeX 控件中播放视频。鼠标点击侦听器触发良好,并按预期工作。但是关键 press/down 听众不会开火。我附上了下面的一些代码,如有任何帮助,我们将不胜感激。

订阅活动

    public void playVideo(string videoPath, bool loop)
    {
        stopTriggered = false;

        this.loop = loop;
        this.videoPath = videoPath;
        this.WindowState = FormWindowState.Normal;
        this.BringToFront();

        m_GolbalHook = Hook.GlobalEvents();
        m_GolbalHook.MouseClick += m_GolbalHook_MouseClick;
        m_GolbalHook.KeyDown += m_GolbalHook_KeyDown;

        axVLCPlugin21.Focus();
        axVLCPlugin21.playlist.items.clear();
        axVLCPlugin21.playlist.add("file:///" + videoPath);
        axVLCPlugin21.AutoLoop = loop;
        axVLCPlugin21_Pos = ScreenPositons.Screen1_Start;

        axVLCPlugin21.playlist.play();
    }

事件触发代码

    private void m_GolbalHook_KeyDown(object sender, KeyEventArgs e)
    {
        //Not triggering at the moment
        switch (e.KeyCode)
        {
            case Keys.Right:
                shiftRight();
                break;
            case Keys.Left:
                shiftLeft();
                break;
        }
    }

发布我使用的解决方案,以防对其他人有所帮助。所有功劳都归功于 Kilazur(见评论)。这不是一个完美的解决方案,但它确实有效...

m_GolbalHook = Hook.GlobalEvents();
m_GolbalHook.MouseClick += m_GolbalHook_MouseClick;

m_AppHook = Hook.AppEvents();
m_AppHook.KeyDown += m_AppHook_KeyDown;

我使用 Hook.GlobalEvents() 作为鼠标监听器,Hook.AppEvents() 作为按键监听器。