Search code examples
c++winapiinputvoipkeyboard-hook

Capturing keyboard input and the consequences of hooks


I am writing a VoIP program and one of the standard features is press-to-talk, meaning while holding down a key you record and send audio. The key will react no matter if you are in a videogame or has focus on another window.

My questions;

  1. do all VoIP programs explicitly use keyboard hooks to achieve this? For example, ventrilo/teamspeak/skype/mumble
  2. I have heard keyboard hooks incur a peformance hit on the system since every keyboard message is sent to the VoIP application too. Is there a way to reduce the cost, and how big is the performance hit? My number one priority in my application is performance and effective, low use of computer resources.

Thanks in advance


Solution

  • Is there a way to reduce the cost, and how big is the performance hit?

    The performance hit and cost are directly proportional to the amount of work your handler code does.

    If you read the documentation it says that these are some of the reasons to do so (emphasis mine):

    1. Monitor messages for debugging purposes
    2. Provide support for recording and playback of macros
    3. Provide support for a help key (F1)
    4. Simulate mouse and keyboard input
    5. Implement a computer-based training (CBT) application