1

I'm using the Global MouseKeyHook to listen, for both mouse clicks and key presses, whilst playing a video in a VLC activeX control. The mouse click listener triggers fine, and works as expected. But the key press/down listeners don't fire. I've attached some of the code below, any help would be appreciated.

Subscribe to the events

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

Event triggered code

    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;
        }
    }
Sandwich
  • 356
  • 7
  • 18
  • Did you try `Hook.AppEvents()` instead of `Hook.GlobalEvents()`? – Kilazur Aug 20 '15 at 13:34
  • I hadn't, and that works, the key listener now fires. But the mouse listener doesn't. I can get round this by having two hooks, one global one app. Thanks for the help! Feel free to add this as an answer and I'll mark it. Otherwise I'll add details to the question, to help anyone else that has this issue. – Sandwich Aug 20 '15 at 13:50
  • That looks weird, but not so much... Actually, the keyboard has a focus, so if it's on your application, it may be possible that the global hook can't get the inputs; as for the mouse, it doesn't have a focus, so the application hook would have trouble getting its inputs. That's just a wild guess. – Kilazur Aug 20 '15 at 14:00
  • Or, you know, I stop saying non-sense and http://stackoverflow.com/questions/30326187/global-hook-mousedown-and-keypress-events-are-not-firing – Kilazur Aug 20 '15 at 14:02

1 Answers1

0

Posting the solution I used, in case it helps others. All credit to Kilazur (see comments). It's not a perfect solution, but it works...

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

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

I'm using Hook.GlobalEvents() for the mouse listener, and Hook.AppEvents() for the key listener.

Sandwich
  • 356
  • 7
  • 18