tags:

views:

351

answers:

2

I want to make an app which on loading sits in the system tray and even after I open another program (say notepad or vlc or anything) i.e. even when the app is not in focus and if I press "G" on my keyboard, the tray icon should show a tool tip - "key G is pressed". I have tried several codes but nothing works when the app goes out of focus. I can use Register Hot Key (http://msdn.microsoft.com/en-us/library/ms646309(VS.85).aspx) but it needs a modifier also (like Ctrl or Alt etc. along with my key G). So, is there any way I can achieve this? something which many tray icons do like antivirus apps, etc. and I do not want to use AutoHotkey application. I want to build one but need some help. Thanks!

A: 

You will need to use Keyboard hook. Here are several implementations: Keyboard hooks

Giorgi
Hey, I already built my app using Hook yday itself. anyways Thanks for the reply. you can check out my app @ http://bit.ly/CapsLockStatus
Avinash Sonee
That's nice. It would be good if you marked the reply that helped you as an answer so that others find it useful too.
Giorgi
A: 

WindowsHookLib.dll have saved me many times. It lets you hook both mouse and keyboard system wide very easy.

http://www.vbforums.com/showthread.php?t=436321

to hook the keyboard and act when 'G' is pressed:

Imports WindowsHookLib
Public Class frmMain

    Dim WithEvents gkh As New LLKeyboardHook

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        gkh.RemoveHook()
        ghk.Dispose()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gkh.InstallHook()
    End Sub


    Private Sub gkh_KeyDown(ByVal sender As Object, ByVal e As WindowsHookLib.KeyEventArgs) Handles gkh.KeyDown
        If e.KeyCode = Keys.G Then
            REM G is pressed!                
        End If
    End Sub
    Private Sub gkh_KeyUp(ByVal sender As Object, ByVal e As WindowsHookLib.KeyEventArgs) Handles gkh.KeyUp
        If e.KeyCode = Keys.G Then
            REM G was pressed and now released
        End If
    End Sub

End Class
Stefan