Global hotkey only works with certain keys?


Dec 4, 2014
Programming Experience
Hi guys,

I'm using VS 2010.

I'm trying to make global hot key to bring up a little form for me which can help me do various functions faster. Such as, open a certain web page, program, etc....

So the hot key I want is Left Control + Windows. Even when the form is minimized or hidden.

With the code I have, I can register single keys such as A-Z and it works. When I try to add control, it fails. I also did get it to work with Alt+[A-Z]

Imports System.Runtime.InteropServices
Public Class frmSpeedLink

<DllImport("User32.dll")> Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
    End Function
    <DllImport("User32.dll")> Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
    End Function

 Private Sub frmSpeedLink_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
       RegisterHotKey(MyBase.Handle, 1, &H11, Keys.LWin) 'Registers Control + left windows (&H11, Keys.LWin)
    End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) 'Processes Windows messages(window processor/wndproc).
        If m.Msg = &H312 Then 'this code &H312 means a hot key was pressed that was registered to this form
        End If


    End Sub

Private Sub frmSpeedLink_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
              UnregisterHotKey(MyBase.Handle, 1) 'unregister the hotkey
    End Sub

End Class

Thank you!
Last edited:
You haven't read the documentation properly for the RegisterHotKey function. Read it now and concentrate on the values accepted for the third parameter.

RegisterHotKey function (Windows)

Latest posts