Public address As Integer 'to store the parallel port address
Public x As Integer
Public output As Integer 'to store the value to be output to be put to the parallel port
Public up, down, lleft, right As Boolean 'to keep track of which buttons are already pressed
Private Declare Sub DlPortWritePortUchar Lib "dlportio.dll" (ByVal Port As Long, ByVal Value As Byte)
'make sure you put dlportio.dll and dlportio.sys into the /windows/sytem32 folder ... or install my rc car software. That'll do it for you.
Private Sub exit_Click(Index As Integer)
Unload Me
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, 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 = vbKeyUp And up <> True Then Label1.ForeColor = &HFF&: output = output + 1: up = True
If KeyCode = vbKeyDown And down <> True Then Label2.ForeColor = &HFF&: output = output + 2: down = True
If KeyCode = vbKeyLeft And lleft <> True Then Label3.ForeColor = &HFF&: output = output + 4: lleft = True
If KeyCode = vbKeyRight And right <> True Then Label4.ForeColor = &HFF&: output = output + 8: right = True
Label6.Caption = output 'This is only for debugging. This is the value that is output to the parallel port
DlPortWritePortUchar address, output 'The command to output to the parallel port
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, 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 = vbKeyUp Then Label1.ForeColor = &H0&: output = output - 1: up = False
If KeyCode = vbKeyDown Then Label2.ForeColor = &H0&: output = output - 2: down = False
If KeyCode = vbKeyLeft Then Label3.ForeColor = &H0&: output = output - 4: lleft = False
If KeyCode = vbKeyRight Then Label4.ForeColor = &H0&: output = output - 8: right = False
Label6.Caption = output 'This is only for debugging. This is the value that is output to the parallel port
DlPortWritePortUchar address, output 'The command to output to the parallel port
End Sub
Private Sub Form_Load()
'Just setting stuff up:
address = 888 'Parallel port address. Change to whatever it needs to be.
'Note: 888 in decimal is 0x378 in hex. Other popular addresses are 658 and 956.
output = 0 'starts output off at 0
Label6.Caption = output
DlPortWritePortUchar address, 0 'makes sure nothing it being output to the parallel port as soon as the program starts.
End Sub
'you can change hotkeys according to your need