CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    2

    Handling special multimedia keyboard keys

    Hi, I'm writing an app where I need to handle the play, pause, stop buttons on multimedia keyboards. I get the WM_APPCOMMAND events while my app has focus and all is well.

    However, when my app is not focused, it never sees the play/stop/etc. I read through Win32 doc for handling keyboard input and it hints under the heading "Keyboard Keys for Browsing and Other Functions" to use SetWindowsHookEX with WH_SHELL.

    If I do that as a local thread hook, my app never sees keys while other apps have focus. I'm pretty sure registering as a global hook will work, BUT

    1) The Win32 docs say never to do that for released software (just bad practice, but I know lots of software does)
    2) I'm afraid of getting flagged by anti-virus software (the real reason I have reservations about this approach)

    How realistic is my fear of running afoul of anti-virus software? I'm not setting a keyboard hook like a key logger would, so maybe a global WH_SHELL hook is more benign?

    I've noticed that Microsoft Media Player gets Play/Stop keys when they aren't focused, and Spy tells me they get it through the WH_SHELL hook. Does that mean they have to have set a global hook?

    Thanks all!
    Gus

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Handling special multimedia keyboard keys

    I would try to use RegisterHotKey Function.
    Check out Virtual-Key Codes, in particular VK_MEDIA_PLAY_PAUSE and other VK_MEDIA_...
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Re: Handling special multimedia keyboard keys

    That works great. Thank you very much Validimir!

  4. #4
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Handling special multimedia keyboard keys

    Quote Originally Posted by maddoxrunner View Post
    That works great. Thank you very much Validimir!
    you are welcome!
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured