On key press, multiple cases
I want it so that for each case you will have to press a key, for example
Case 1 - You have to press "I"
Case 2 - You have to press "V"
etc, thanks!
Code:
Private Sub imgButton_Click(Index As Integer)
Dim Buffer As clsBuffer
Dim i As Long
' If debug mode, handle error then exit out
If Options.Debug = 1 Then On Error GoTo errorhandler
Select Case Index
Case 1
If Not picInventory.Visible Then
' show the window
picInventory.Visible = True
picCharacter.Visible = False
picSpells.Visible = False
picOptions.Visible = False
picParty.Visible = False
Picture5.Visible = True
BltInventory
' play sound
PlaySound Sound_ButtonClick
Else
Picture5.Visible = False
End If
Case 2
If Not picSpells.Visible Then
' send packet
Set Buffer = New clsBuffer
Buffer.WriteLong CSpells
SendData Buffer.ToArray()
Set Buffer = Nothing
' show the window
picSpells.Visible = True
picInventory.Visible = False
picCharacter.Visible = False
picOptions.Visible = False
picParty.Visible = False
Picture5.Visible = True
' play sound
PlaySound Sound_ButtonClick
Else
Picture5.Visible = False
End If
Case 3
If Not picCharacter.Visible Then
' send packet
SendRequestPlayerData
' show the window
picCharacter.Visible = True
picInventory.Visible = False
picSpells.Visible = False
picOptions.Visible = False
picParty.Visible = False
Picture5.Visible = True
' play sound
PlaySound Sound_ButtonClick
' Render
BltEquipment
BltFace
Else
Picture5.Visible = False
End If
Case 4
If Not picOptions.Visible Then
' show the window
picCharacter.Visible = False
picInventory.Visible = False
picSpells.Visible = False
picOptions.Visible = True
picParty.Visible = False
Picture5.Visible = True
' play sound
PlaySound Sound_ButtonClick
Else
Picture5.Visible = False
End If
Case 5
SendTradeRequest
Case 6
' logoutGame
If Not picParty.Visible Then
' show the window
picCharacter.Visible = False
picInventory.Visible = False
picSpells.Visible = False
picOptions.Visible = False
picParty.Visible = True
Picture5.Visible = True
' play sound
PlaySound Sound_ButtonClick
Else
Picture5.Visible = False
End If
End Select
' Error handler
Exit Sub
errorhandler:
HandleError "imgButton_Click", "frmMain", Err.Number, Err.Description, Err.Source, Err.HelpContext
Err.Clear
Exit Sub
End Sub
Re: On key press, multiple cases
You mean something like this:
vb Code:
Option Explicit
Private Sub Form_KeyPress(KeyAscii As Integer)
If (KeyAscii = Asc("A")) Or (KeyAscii = Asc("a")) Then '~~~ Check if the pressed key is "A" or "a"
MsgBox "You pressed 'A' "
End If
End Sub
Private Sub Form_Load()
'~~~ This needs to be made TRUE inorder to work
Me.KeyPreview = True
End Sub
:wave:
Re: On key press, multiple cases
If I understand you correctly, you want certain keystrokes to simulate a imgButton_Click event, where "I" is equivalent to clicking on imgButton(1), etc?
If so, then another option is to provide a menu with Ctrl+keys. The menu might be called "View" with submenu items for Inventory, Spelling, Character, Options, etc. With each menu item, you can set the shortcut for it. Suggestion, if using menus for other things, do not use menu keys common to most typical menu items (File, Edit, etc) for those submenu items; i.e., don't use Ctrl+V as that is known world-wide for a Paste shortcut & used in textboxes.