does any one know about using hot keys in a 2005 app?
I posted a similar question in VB but was probably in the wrong forum. I want to be able to send text to a comport if a certain key is held for 2 seconds. I can get this to work with the app in focus but i would like it to work from the back ground as well. I would appreciate a push in the right direction, not looking for anyone to do my code for me. Thanks
Expand|Select|Wrap|Line Numbers
- Public Class frmKeyCatcher
- Dim WithEvents serialPort As New IO.Ports.SerialPort
- Private Sub DataReceived( _
- ByVal sender As Object, _
- ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
- Handles serialPort.DataReceived
- txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), _
- New Object() {})
- End Sub
- Public Delegate Sub myDelegate()
- Public Sub updateTextBox()
- With txtDataReceived
- .SelectionColor = Color.Red
- .AppendText(serialPort.ReadExisting)
- .ScrollToCaret()
- End With
- End Sub
- Private Sub frmKeyCatcher_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- serialPort.Close()
- End Sub
- Private Sub frmKeyCatcher_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
- If e.KeyCode = 49 Then
- Timer1.Start()
- End If
- End Sub
- Private Sub frmKeyCatcher_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
- If e.KeyCode = 49 Then
- Timer1.Stop()
- End If
- End Sub
- Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Me.Show()
- Me.BackColor = Color.LightGray
- If serialPort.IsOpen Then
- serialPort.Close()
- End If
- Try
- With serialPort
- .PortName = "COM3"
- .BaudRate = 9600
- .Parity = IO.Ports.Parity.None
- .DataBits = 8
- .StopBits = IO.Ports.StopBits.One
- End With
- serialPort.Open()
- Timer4.Start()
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- End Sub
- Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
- Me.Hide()
- Timer2.Stop()
- End Sub
- Private Sub Timer4_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer4.Tick
- Try
- serialPort.Write("C")
- With txtDataReceived
- .SelectionColor = Color.Black
- .AppendText("C" & vbCrLf)
- .ScrollToCaret()
- End With
- Me.BackColor = Color.white
- Catch ex As Exception
- End Try
- Timer4.Stop()
- Timer2.Start()
- End Sub
- End Class