Reading Keypad under VB6
This is pretty easy. When you intialise MScomm, you need to set the RThreshold to 1 and InputLen to 1. You can then use the OnComm event. Read up on this in the VB help file. When data is received by the port, OnComm is fired and you can then react and find out what "key" was pressed.This code is taken direct from my project. I use XMComm control rather than MSComm but they are the same.
Private Sub XMComm2_OnComm()
Static LastKeyPress As String
XMComm2.Output = Chr$(&HFE) & Chr$(&H42) & Chr$(&H1) 'backlight on
bufferLCD = XMComm2.Input
If LastKeyPress = "D" Then
If bufferLCD = "I" Then
vol = True
lcdVolControl (bufferLCD)
WinAMP_PressPlay
Exit Sub
End If
End If
Select Case bufferLCD
Case "C"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressPlay
Text4.Text = "Play"
Case "E"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressStop
Text4.Text = "Stop"
Case "B"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressFFWD
Text4.Text = "Fast Forward"
Case "G"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressRWD
Text4.Text = "Rewind"
Case "J"
If vol = False Then
UpAnAlbum
Text4.Text = "Up An Album"
End If
If vol = True Then
lcdVolControl (bufferLCD)
elapsedsecs = 0
LastKeyPress = ""
End If
Case "H"
If vol = False Then
DownAnAlbum
Text4.Text = "Down An Album"
End If
If vol = True Then
lcdVolControl (bufferLCD)
elapsedsec = 0
LastKeyPress = ""
End If
Case "I"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
AlbumSelected
Text4.Text = "Album Selected"
Case "D"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_Pause
Text4.Text = "Paused"
Case "9"
InitialiseLCD
End Select
LastKeyPress = bufferLCD
buffer1 = ""
bufferLCD = ""
XMComm2.InBufferCount = 0
End Sub
This should help. If you are still stuck, post again.
Babber
Private Sub XMComm2_OnComm()
Static LastKeyPress As String
XMComm2.Output = Chr$(&HFE) & Chr$(&H42) & Chr$(&H1) 'backlight on
bufferLCD = XMComm2.Input
If LastKeyPress = "D" Then
If bufferLCD = "I" Then
vol = True
lcdVolControl (bufferLCD)
WinAMP_PressPlay
Exit Sub
End If
End If
Select Case bufferLCD
Case "C"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressPlay
Text4.Text = "Play"
Case "E"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressStop
Text4.Text = "Stop"
Case "B"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressFFWD
Text4.Text = "Fast Forward"
Case "G"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_PressRWD
Text4.Text = "Rewind"
Case "J"
If vol = False Then
UpAnAlbum
Text4.Text = "Up An Album"
End If
If vol = True Then
lcdVolControl (bufferLCD)
elapsedsecs = 0
LastKeyPress = ""
End If
Case "H"
If vol = False Then
DownAnAlbum
Text4.Text = "Down An Album"
End If
If vol = True Then
lcdVolControl (bufferLCD)
elapsedsec = 0
LastKeyPress = ""
End If
Case "I"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
AlbumSelected
Text4.Text = "Album Selected"
Case "D"
If vol = True Then
vol = False
LCDOutPut
winampTimer = True
Exit Sub
End If
WinAMP_Pause
Text4.Text = "Paused"
Case "9"
InitialiseLCD
End Select
LastKeyPress = bufferLCD
buffer1 = ""
bufferLCD = ""
XMComm2.InBufferCount = 0
End Sub
This should help. If you are still stuck, post again.
Babber