private Sub KeyPressHandler(kval As Byte)
Select kval 'SCAN CODE IS THE SAME FOR ANY 4X4 KEYPAD, JUST DECODE ASCIIs ACCORDING TO WHAT IS PRINTED ON KEYPAD KEY
Case KEY_1 '1, ROW0 COL0
KeyASCII(0) = 0x31
Case KEY_2 '2, ROW0 COL1
KeyASCII(0) = 0x32
Case KEY_3 '3, ROW0 COL2
KeyASCII(0) = 0x33
Case KEY_4 '4, ROW1 COL0
KeyASCII(0) = 0x34
Case KEY_5 '5, ROW1 COL1
KeyASCII(0) = 0x35
Case KEY_6 '6, ROW1 COL2
KeyASCII(0) = 0x36
Case KEY_7 '7, ROW2 COL0
KeyASCII(0) = 0x37
Case KEY_8 '8, ROW2 COL1
KeyASCII(0) = 0x38
Case KEY_9 '9, ROW2 COL2
KeyASCII(0) = 0x39
Case KEY_STAR'*, ROW3 COL0
KeyASCII(0) = 0x2A
Case KEY_0 '0, ROW3 COL1
KeyASCII(0) = 0x30
Case KEY_NUM'#, ROW3 COL2
KeyASCII(0) = 0x23
Case KEY_F1 'F1,ROW1 COL0
KeyASCII(0) = 0x41
Case KEY_F2 'F2,ROW2 COL1
KeyASCII(0) = 0x42
Case KEY_F3 'F3,ROW2 COL2
KeyASCII(0) = 0x43
Case KEY_F4 'F4,ROW2 COL3
KeyASCII(0) = 0x44
End Select
Log("key: ",kval, " ascii ",KeyASCII)
Select ScreenType
Case SCREEN_TYPE_MAIN
If KeyValue = KEY_1 Then UpdateShift 'shift in, shift out, or count
If KeyValue = KEY_2 Then UpdateReasonCode 'general or undefined, job related assignment i.e out to buy spare parts, stationary..etc, or permitted leave
If KeyValue = KEY_3 Then UpdateLoadType 'vehicle loaded, unloaded or empty
If KeyValue = KEY_F1 Then SCREEN_TYPE_ENTRY 'just test for now, changed state from normal mode to entry mode
Case SCREEN_TYPE_ENTRY
If KeyValue = KEY_NUM Then '# pressed, cancel and return to normal mode
Clear
ScreenType = SCREEN_TYPE_MAIN
End If
Dim RAF As RandomAccessFile
RAF.Initialize(EntryBuffer,False)
RAF.CurrentPosition = EntryBufferIndex
RAF.WriteByte(KeyASCII(0),RAF.CurrentPosition) 'store pressed keys one after another in array
EntryBufferIndex = EntryBufferIndex + 1
Clear
PutString(0,0,BC.StringFromBytes(EntryBuffer),FontArial5x8,False) 'display the array on lcd
End Select
End Sub