Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The little help, I want to make a customize each individual hotkey.
but I have a problem if my app is not focused hotkeys does not work
any idea?
VB
Public Class Form1

Private KeySelections As New Dictionary(Of String, Keys)

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

    KeySelections.Add("Home", Keys.Home)
    KeySelections.Add("Insert", Keys.Insert)

    ComboBox1.Items.AddRange(KeySelections.Keys.ToArray)
End Sub

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

    If ComboBox1.SelectedIndex > -1 Then 

        Dim hotkey As Keys = KeySelections.Item(ComboBox1.SelectedItem.ToString)

        If keyData = hotkey Then 
            Me.Timer1.Enabled = Not Me.Timer1.Enabled    
            If Timer1.Enabled Then
                Label1.Text = "Timer 1 On"
            Else
                Label1.Text = "Timer 1 Off"
            End If
        End If

    End If

    Return MyBase.ProcessCmdKey(msg, keyData)
End Function
End Class
Posted
Comments
Suvendu Shekhar Giri 8-Oct-15 13:46pm    
But why you want to make enable hot keys when the app window itself is not active?
How does it make any sense?
Hugo1985 8-Oct-15 13:55pm    
OK. So how do I do?
CoderzF1 10-Oct-15 1:24am    
you will have to subclass the global keyboard events if you want to have hot keys to work when the window does not have focus. for more info, search for keyboard hooking.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900