I'm doing an application that minimizes to the system tray on closing or minimizing.For some reason the application do not respond to keyboard event when it's minimized or closed to the system tray.It's working fine as long as the main window is visible.
Basically it's a VB application connected to a microcontroller via USB.When I turn a rotary encoder it turns the volume up.
Here is part of my code:
Basically it's a VB application connected to a microcontroller via USB.When I turn a rotary encoder it turns the volume up.
Here is part of my code:
Code:
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
Const KEYEVENTF_KEYUP As Long = &H2
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
' The user did not click the context menu's Exit command Shrink to the tray
e.Cancel = True
Me.Hide()
Me.ShowInTaskbar = False
ContextMenuStrip1.Enabled = True
NotifyIcon1.Visible = True
End Sub
'*****************************************************************
' on read event...
'*****************************************************************
Public Sub OnRead(ByVal pHandle As Integer)
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontroller...
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
USB_Receive_Box.Text = BufferIn(2)
'Volume up
Try
If BufferIn(2) = 45 Then
timer1.Enabled = False
Call keybd_event(Keys.VolumeUp, 0, 0, 0)
timer1.Enabled = True 'repart le timer
End If
Catch ex As Exception
End Try
Try
'Volume down
If BufferIn(2) = 46 Then
timer1.Enabled = False
Call keybd_event(Keys.VolumeDown, 0, 0, 0)
timer1.Enabled = True 'repart le timer
End If
Catch ex As Exception
End Try
End If
End Sub