Hi,
I am trying to get a menu item only appear on a certain key press and then disappear after a certain time.
this is working for the first time only once hidden it will not appear.
I am using RegisterHotKey on the keydown event please see the code below if anyone has a better way of getting this achieved please let me know.
Code:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If RegisterHotKey(Me.Handle, 100, MOD_Alt, Keys.X) Then 'alt+x
MenuStrip1.Visible = True
Timer1.Enabled = True
Timer1.Start()
End If
End Sub
Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_HOTKEY Then
Dim id As IntPtr = m.WParam
Select Case (id.ToString)
Case "100"
MessageBox.Show("Alt+X Key Press Detected Loading Admin Center", "Admin Center", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Select
End If
MyBase.WndProc(m)
End Sub
Code:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
MenuStrip1.Visible = False
Timer1.Stop()
End Sub
Code:
Public Const MOD_Alt As Integer = &H1
Public Const WM_HOTKEY As Integer = &H312
<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
Cheers James