Public Class Form1
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Public up, down, lleft, rright As Boolean 'to keep track of which buttons are already pressed
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CardAddress As Integer
Dim h As Integer
CardAddress = 3
h = OpenDevice(3)
Label1.Text = "Card " + Str(h) + " connected"
End Sub
Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
'------------------------------------------------------------------'
'This section of code detects which key is being pressed. Once the
'key is pressed, it changes the colour of the label to red and adds the
'correct value to ouput. 1,2,4,8 are the correct values. To write
'to the parallel port, it's done in binary. 1 in binary is 00000001
'2 in binary is 00000010, 4 in binary is 00000100, 8 in binary is 00001000
'so by saying "out DlPortWritePortUchar, 4" we are actually turning on one pin of the parallel port
'If we say "out 888, (1+2)" or "DlPortWritePortUchar 888, 3" we are turning on two pins, pins 1 and 2.
'-------------------------------------------------------------------'
If (KeyCode = 38) And up <> True Then Label2.ForeColor = Color.Red : up = True
If (KeyCode = 40) And down <> True Then Label2.ForeColor = Color.Red : down = True
If (KeyCode = 37) And lleft <> True Then Label3.ForeColor = Color.Red : lleft = True
If (KeyCode = 39) And rright <> True Then Label4.ForeColor = Color.Red : rright = True
End Sub
Private Sub Form_KeyUp(ByVal KeyCode As Integer, ByVal Shift As Integer)
'------------------------------------------------------------------'
'This section of code detects when a pressed key has been lifted.
'changes the label's colour back to black and subtracts a value from
'output. It does the opposite of the keydown code, in that it turns
'off a parallel pin rather than turning it on.
'-------------------------------------------------------------------'
If (KeyCode = 38) Then Label1.ForeColor = Color.Black : up = False
If (KeyCode = 40) Then Label2.ForeColor = Color.Black : down = False
If (KeyCode = 37) Then Label3.ForeColor = Color.Black : lleft = False
If (KeyCode = 39) Then Label4.ForeColor = Color.Black : rright = False
End Sub
End Class