i want to make a hotkeys app ...

i need to detect keystrokes even if the form is not active so that by pressing a button i can launh the calculator.... or games and stuff like that...

any ideas ?

Thank you

9 Years
Discussion Span
Last Post by Dell XPS

can you write an example of the code needed to do this because i dont understand this by reading it in the msdn....

Thank you


I give example using Win32 API. You have to refer it. I am not sure it is error free. But just try
Draw a form and Try this code. Run the Project. Press Ctrl + Alt + Up Arrow

Public Enum HotKeyModifiers As Integer
        MOD_ALT = &H1
        MOD_CONTROL = &H2
        MOD_SHIFT = &H4
        MOD_WIN = &H8
    End Enum
    Private Const WM_HOTKEY As Integer = &H312
    Public Declare Auto Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
    Public Declare Auto Function UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer) As Boolean

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RegisterHotKey(Me.Handle, 1020, HotKeyModifiers.MOD_ALT Or HotKeyModifiers.MOD_CONTROL, Keys.Up)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        UnregisterHotKey(Me.Handle, 1020)
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If (m.Msg = WM_HOTKEY) Then
            Dim hotKeyId As Integer = m.WParam.ToInt32()
            If hotKeyId = 1020 Then
                MsgBox("Hot Key Pressed")
            End If
        End If
    End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.