T.Jackson
- 9th May 2007, 07:34
Be great if PBP supported ELSEIF structure - something a bit like the following...
ElseIf GetAsyncKeyState(vbKeyF1) Then '(F1) Show palette
If Key_Pressed(vbKeyF1) = 0 Then 'Key not held down?
LED_Palette.Show 'Show palette
Key_Pressed(vbKeyF1) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF6) Then '(F6) Next frame
If Key_Pressed(vbKeyF6) = 0 Then 'Key not held down?
Adj_Button = 0 'Set flag
Call Apply_Frame_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF6) = 1 'Set flag
End If
ELSEIF can be quite advantageously in some cases, consider the following complex procedure and how it would need to be done if, ELSEIF wasn't supported in VB
<hr/>
Public Sub Poll_Keyboard()
'-----------------------------------------------------------------------------
'// Check for menu control keys, ESC terminates app, all other keys restore
' menu and cursor if they have been turned off. Proc includes key de bounce
'-----------------------------------------------------------------------------
Dim i As Long 'General working var
If GetAsyncKeyState(vbKeyEscape) Then 'Quit (ESC)
Terminate_App = True 'Set flag
'-----------------------------------------------------------------------------
'// Check combination keys first
'-----------------------------------------------------------------------------
ElseIf GetAsyncKeyState(vbKeyControl) Then 'CTRL key down?
If Popup_Insert.Enabled Then 'Legal operation?
If GetAsyncKeyState(vbKeyI) Then 'CTRL+I Insert
Call Popup_Insert_Click 'Jump to proc
Exit Sub 'Bail out
End If
End If
If Popup_Save.Enabled Then 'Legal operation?
If GetAsyncKeyState(vbKeyShift) Then 'Shift?
If GetAsyncKeyState(vbKeyS) Then 'Shift+CTRL+S Save As
Call Initiate_ROM_Save("Save As *.bin") 'Jump to proc
Exit Sub 'Bail out
End If
End If
If Not Run_ROM Then
If GetAsyncKeyState(vbKeyN) Then '(CTRL + N) New
Call New_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
If GetAsyncKeyState(vbKeyO) Then '(CTRL + O) Load
Call Load_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
End If
'//
Else '(always allow open or load, if not running)
'//
If GetAsyncKeyState(vbKeyN) Then '(CTRL + N) New
Call New_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
If GetAsyncKeyState(vbKeyO) Then '(CTRL + O) Load
Call Load_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
End If
'-----------------------------------------------------------------------------
'// Function keys with no CTRL, all used except (10-12)
'-----------------------------------------------------------------------------
ElseIf GetAsyncKeyState(vbKeyF1) Then '(F1) Show palette
If Key_Pressed(vbKeyF1) = 0 Then 'Key not held down?
LED_Palette.Show 'Show palette
Key_Pressed(vbKeyF1) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF6) Then '(F6) Next frame
If Key_Pressed(vbKeyF6) = 0 Then 'Key not held down?
Adj_Button = 0 'Set flag
Call Apply_Frame_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF6) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF7) Then '(F7) Previous frame
If Key_Pressed(vbKeyF7) = 0 Then 'Key not held down?
Adj_Button = 1 'Set flag
Call Apply_Frame_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF7) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF8) Then '(F8) Next group
If Key_Pressed(vbKeyF8) = 0 Then 'Key not held down?
Adj_Button = 4 'Set flag
Call Apply_Group_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF8) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF9) Then '(F9) Previous group
If Key_Pressed(vbKeyF9) = 0 Then 'Key not held down?
Adj_Button = 5 'Set flag
Call Apply_Group_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF9) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF5) Then '(F5) Run
If Key_Pressed(vbKeyF5) = 0 Then 'Key not held down?
Call Run_Click 'Jump to proc
Key_Pressed(vbKeyF5) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF2) Then '(F2) Pause
If Key_Pressed(vbKeyF2) = 0 Then 'Key not held down?
Call Pause_Click 'Jump to proc
Key_Pressed(vbKeyF2) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF3) Then '(F3) Reset
If Key_Pressed(vbKeyF3) = 0 Then 'Key not held down?
Call Reset_Click 'Jump to proc
Key_Pressed(vbKeyF3) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF8) Then '(F8) Jump to
If Not Key_Pressed(vbKeyF8) Then 'Key not held down?
Call Jump_To_Frame_Click 'Jump to proc
Key_Pressed(vbKeyF8) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF9) Then '(F9) Dump
If Key_Pressed(vbKeyF9) = 0 Then 'Key not held down?
Call Dump_Click 'Jump to proc
Key_Pressed(vbKeyF9) = 1 'Set key flag
End If
ElseIf GetAsyncKeyState(vbKeyDelete) Then '(Del) All Off
If Total_Frames <> 0 Then 'Legal operation?
If Key_Pressed(vbKeyDelete) = 0 Then 'Key not held down?
Call All_Off_Click 'Jump to proc
Key_Pressed(vbKeyDelete) = 1 'Set flag
End If
End If
'-----------------------------------------------------------------------------
Else '// Any other key press restores menu & cursor (if switched off)
'-----------------------------------------------------------------------------
If Not Menu.Visible Then
For i = 0 To 255 'Test for keys
If GetAsyncKeyState(i) Then '
Menu.Visible = True 'Restore
Title.Visible = True '
Credits.Visible = True '
Call ShowCursor(True) 'Mouse pointer
'//
If Palette_Active Then 'Palette visible prior?
LED_Palette.Show 'Restore it
End If '
Exit For 'Bail out (no time wasted)
End If
Next
End If
End If
'-----------------------------------------------------------------------------
'// Reset flags if keys are up
'-----------------------------------------------------------------------------
For i = 0 To 255 'Scan through all keys
If GetAsyncKeyState(i) = 0 Then 'Key held down?
Key_Pressed(i) = 0 'Reset flag if not
End If '
Next '
End Sub
ElseIf GetAsyncKeyState(vbKeyF1) Then '(F1) Show palette
If Key_Pressed(vbKeyF1) = 0 Then 'Key not held down?
LED_Palette.Show 'Show palette
Key_Pressed(vbKeyF1) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF6) Then '(F6) Next frame
If Key_Pressed(vbKeyF6) = 0 Then 'Key not held down?
Adj_Button = 0 'Set flag
Call Apply_Frame_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF6) = 1 'Set flag
End If
ELSEIF can be quite advantageously in some cases, consider the following complex procedure and how it would need to be done if, ELSEIF wasn't supported in VB
<hr/>
Public Sub Poll_Keyboard()
'-----------------------------------------------------------------------------
'// Check for menu control keys, ESC terminates app, all other keys restore
' menu and cursor if they have been turned off. Proc includes key de bounce
'-----------------------------------------------------------------------------
Dim i As Long 'General working var
If GetAsyncKeyState(vbKeyEscape) Then 'Quit (ESC)
Terminate_App = True 'Set flag
'-----------------------------------------------------------------------------
'// Check combination keys first
'-----------------------------------------------------------------------------
ElseIf GetAsyncKeyState(vbKeyControl) Then 'CTRL key down?
If Popup_Insert.Enabled Then 'Legal operation?
If GetAsyncKeyState(vbKeyI) Then 'CTRL+I Insert
Call Popup_Insert_Click 'Jump to proc
Exit Sub 'Bail out
End If
End If
If Popup_Save.Enabled Then 'Legal operation?
If GetAsyncKeyState(vbKeyShift) Then 'Shift?
If GetAsyncKeyState(vbKeyS) Then 'Shift+CTRL+S Save As
Call Initiate_ROM_Save("Save As *.bin") 'Jump to proc
Exit Sub 'Bail out
End If
End If
If Not Run_ROM Then
If GetAsyncKeyState(vbKeyN) Then '(CTRL + N) New
Call New_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
If GetAsyncKeyState(vbKeyO) Then '(CTRL + O) Load
Call Load_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
End If
'//
Else '(always allow open or load, if not running)
'//
If GetAsyncKeyState(vbKeyN) Then '(CTRL + N) New
Call New_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
If GetAsyncKeyState(vbKeyO) Then '(CTRL + O) Load
Call Load_ROM_Click 'Jump to proc
Exit Sub 'Bail out
End If
End If
'-----------------------------------------------------------------------------
'// Function keys with no CTRL, all used except (10-12)
'-----------------------------------------------------------------------------
ElseIf GetAsyncKeyState(vbKeyF1) Then '(F1) Show palette
If Key_Pressed(vbKeyF1) = 0 Then 'Key not held down?
LED_Palette.Show 'Show palette
Key_Pressed(vbKeyF1) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF6) Then '(F6) Next frame
If Key_Pressed(vbKeyF6) = 0 Then 'Key not held down?
Adj_Button = 0 'Set flag
Call Apply_Frame_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF6) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF7) Then '(F7) Previous frame
If Key_Pressed(vbKeyF7) = 0 Then 'Key not held down?
Adj_Button = 1 'Set flag
Call Apply_Frame_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF7) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF8) Then '(F8) Next group
If Key_Pressed(vbKeyF8) = 0 Then 'Key not held down?
Adj_Button = 4 'Set flag
Call Apply_Group_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF8) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF9) Then '(F9) Previous group
If Key_Pressed(vbKeyF9) = 0 Then 'Key not held down?
Adj_Button = 5 'Set flag
Call Apply_Group_Num_Adj 'Jump to proc
Key_Pressed(vbKeyF9) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF5) Then '(F5) Run
If Key_Pressed(vbKeyF5) = 0 Then 'Key not held down?
Call Run_Click 'Jump to proc
Key_Pressed(vbKeyF5) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF2) Then '(F2) Pause
If Key_Pressed(vbKeyF2) = 0 Then 'Key not held down?
Call Pause_Click 'Jump to proc
Key_Pressed(vbKeyF2) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF3) Then '(F3) Reset
If Key_Pressed(vbKeyF3) = 0 Then 'Key not held down?
Call Reset_Click 'Jump to proc
Key_Pressed(vbKeyF3) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF8) Then '(F8) Jump to
If Not Key_Pressed(vbKeyF8) Then 'Key not held down?
Call Jump_To_Frame_Click 'Jump to proc
Key_Pressed(vbKeyF8) = 1 'Set flag
End If
ElseIf GetAsyncKeyState(vbKeyF9) Then '(F9) Dump
If Key_Pressed(vbKeyF9) = 0 Then 'Key not held down?
Call Dump_Click 'Jump to proc
Key_Pressed(vbKeyF9) = 1 'Set key flag
End If
ElseIf GetAsyncKeyState(vbKeyDelete) Then '(Del) All Off
If Total_Frames <> 0 Then 'Legal operation?
If Key_Pressed(vbKeyDelete) = 0 Then 'Key not held down?
Call All_Off_Click 'Jump to proc
Key_Pressed(vbKeyDelete) = 1 'Set flag
End If
End If
'-----------------------------------------------------------------------------
Else '// Any other key press restores menu & cursor (if switched off)
'-----------------------------------------------------------------------------
If Not Menu.Visible Then
For i = 0 To 255 'Test for keys
If GetAsyncKeyState(i) Then '
Menu.Visible = True 'Restore
Title.Visible = True '
Credits.Visible = True '
Call ShowCursor(True) 'Mouse pointer
'//
If Palette_Active Then 'Palette visible prior?
LED_Palette.Show 'Restore it
End If '
Exit For 'Bail out (no time wasted)
End If
Next
End If
End If
'-----------------------------------------------------------------------------
'// Reset flags if keys are up
'-----------------------------------------------------------------------------
For i = 0 To 255 'Scan through all keys
If GetAsyncKeyState(i) = 0 Then 'Key held down?
Key_Pressed(i) = 0 'Reset flag if not
End If '
Next '
End Sub