Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that will minimize on tray icon when Esc is press
VB
Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    If e.KeyCode = Keys.Escape Then
        Me.WindowState = FormWindowState.Minimized
        NotifyIcon1.Visible = True
        Me.Hide()
    End If
End Sub

What I want is make that form appear when I press another hot key (Ctrl+Q) when the form is minimized as system tray

I found this but it is in VB6 codes
http://www.vbforums.com/showthread.php?394845-RESOLVED-Detect-a-Hot-Key-without-looping&highlight=RegisterHotKey[^]
Posted
Updated 30-Apr-14 1:40am
v4

I would use ProcessCmdKey for that ESC Button.. Form.KeyDown never worked well for me ;)

VB
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
        If keyData = Keys.Escape Then
             Console.WriteLine("Yeha Esc pushed..")
             Return True
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
   End Function



Back then in VB6 I used GetAsyncKeyState when I needed to detect Keys pressed outside my App. But unfortunately you need an extra Thread or an Timer for that, as you allways need to check if your Keys are pressed. Don't know if there are better ways now, never needed that functionality in the last years... ^^
(I guess 4 sure there are, but I don't know em)

Here is a litte example
VB
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As IntPtr) As IntPtr
Private Sub Timer_Or_Thread_WhateverRoutine
    Dim result As IntPtr = GetAsyncKeyState(New IntPtr(Keys.F5))
    If result.ToInt32 < 0 Then
        MessageBox.Show("F5 Pushed")
    End If
End Sub
 
Share this answer
 
This CodeProject article should help you Simple steps to enable Hotkey and ShortcutInput user control[^]
 
Share this answer
 

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