GabKeyboardHook

GabKeyboardHook

Introduction

GabKeyboardHook is a library that allows you to intercept any keyboard input, even if your application has not the focus. This is really useful if you need to provide some global hot-keys for your application! It has been inspired by the excellent article of George Mamaladze, some code and comments are even unmodified.

Features

  • Small: the compiled GabKeyboardHook binary is only 8 KB !
  • Fast and efficient.
  • Minimal memory footprint.
  • Convenient. Settings global hot-keys is explained below.
  • Possibility to mark the intercepted keys as handled or not.

GabKeyboardHook is used in several of our applications, including GabCopyPaste, GabMouseColorPicker, GabScreenshot, GabPlayer 2 ans several other internal projects. It has proven to be stable and reliable enough over the years to release it.

Usage

Using GabKeyboardHook is quite straightforward. Just follow these steps:

  1. Add a reference to GabKeyboardHook to your project
  2. Add a member into your class:
    Friend WithEvents keyHook As GabKeyboardHook
  3. Add the following line into the constructor of your class or the Load event of your form:
    Me.keyHook = New GabKeyboardHook(True)
  4. Add the following line into the destructor of your class or the FormClosed event of your form:
    Me.keyHook.Stop(True, False)
  5. Add an event handler into your class:
    Private Sub keyHook_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles keyHook.KeyDown
    
    Me.ProcessKeys(e)
    
    End Sub
  6. Add the ProcessKeys procedure into your class:
    Private Sub ProcessKeys(ByVal touche As System.Windows.Forms.KeyEventArgs)
    
     Select Case True
    
     'for example, this will intercept CTRL+SHIFT+V and handle it
     Case touche.Control And touche.Shift And touche.KeyCode = Keys.V
     touche.Handled = True
     '(your code here)
     Exit Select
    
     'another example: intercept CTRL+C but do not handle it
    Case touche.KeyCode = Keys.C And touche.Control
     touche.Handled = False
     '(your code here)
     Exit Select
    
     End Select
    
    End Sub

Note

It is not a problem to have several instances of the library running each in a different application, but you should avoid to intercept identical keys in different applications because you can’t predict which application will intercept the key first.

Download

Please go to the following Download section.

License

The license is the same as the one George Mamaladze use for his code, and we claim no copyright on it.

Related Post