I made a game with a 'Hide' button. This hides the game. I'd like the user to be able to press a certain key to either exit or make the game visible again.
Any ideas on how to do this?
Thanks
Printable View
I made a game with a 'Hide' button. This hides the game. I'd like the user to be able to press a certain key to either exit or make the game visible again.
Any ideas on how to do this?
Thanks
What do you mean by Hide? Is it a picturebox on which your game is on that you hide, or do you minimze it or do you just make the window invisible?
hmmm try this:
Hope that helped a bit!Code:'When the user presses V it either hides or show the form.
'When pressing C it closes the form
'Place another form in your project (Form2)
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyV Then
Form2.Visible = Not Form2.Visible
End If
If KeyCode = vbKeyC Then Unload Form2
End Sub
Private Sub Form_Load()
KeyPreview = True
Form2.Show , Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim frm As Form
For Each frm In Forms
Unload frm
Set frm = Nothing
Next
End
End Sub
If the Form doesn't have focus then use GetAsyncKeyState API.
Add the following to a Form with a Timer
Code:Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Sub UnloadForms
Dim frm As Form
For Each frm In Forms
Unload frm
Set frm = Nothing
Next frm
End Sub
Private Sub Timer1_Timer()
'Show Form1 if C is pressed
If GetAsyncKeyState(vbKeyC) Then Form1.Show
'Unload if Q is pressed
If GetAsyncKeyState(vbKeyQ) Then UnloadForms
End Sub