|
-
Nov 1st, 2000, 11:33 AM
#1
Thread Starter
Junior Member
Hello, we are trying to make a game application where one of the users presses a button when he/she knows the answer.
Here is the code we have experimented with:
If Chr(KeyAscii) = "a" Or Chr(KeyAscii) = "A" Then
msgbox "you pressed A"
End If
this code snippet works in a new project, but for some reason it will not work in ours.
This might be because there are other procedures going on
I.E. a timer we have counting down. Please help us if you know how we can make this work properly.
-
Nov 1st, 2000, 11:40 AM
#2
Frenzied Member
I can't tell you when you don't post some code, but maybe this code is easier to read 
Code:
If UCase(Chr(KeyAscii) = "A") Then msgbox "you pressed A"
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 1st, 2000, 12:20 PM
#3
New Member
If you think the timer is preventing the execution of that code snippet you could disable then enable the timers with the keydown and keyup events. usin this structure:
Form1_KeyDown(KeyCode as Integer, Shift as Integer)
Timer1.enabled = false
'print the message over here using your code snippet
End Sub
Form1_KeyUp(KeyCode as Integer, Shift as Integer)
Timer1.enabled = True
End Sub
What this does is ensure that the timers are not working as for the short moment when the key is pressed. If you have more than one timer insert this procedure to disable all of them in the keydown event.
Public Sub DisableTimers()
For each Control in Form1.controls
If TypeOf Control Is Timer then
control.enabled = false
End if
Next Control
To then re-enable the timers call this procedure in the key up event.
Public Sub EnableTimers()
For each Control in Form1.controls
If TypeOf Control Is Timer then
control.enabled = true
End if
Next Control
Hope this works if you have probs with it mail me at [email protected] .....I'll be glad to help, I have made a game making heavy use of timers before..I know it can get quite hassling. Enjoy.
-
Nov 1st, 2000, 12:25 PM
#4
New Member
If you think the timer is preventing the execution of that code snippet you could disable then enable the timers with the keydown and keyup events. usin this structure:
Form1_KeyDown(KeyCode as Integer, Shift as Integer)
Timer1.enabled = false
'print the message over here using your code snippet
End Sub
Form1_KeyUp(KeyCode as Integer, Shift as Integer)
Timer1.enabled = True
End Sub
What this does is ensure that the timers are not working as for the short moment when the key is pressed. If you have more than one timer insert this procedure to disable all of them in the keydown event.
Public Sub DisableTimers()
For each Control in Form1.controls
If TypeOf Control Is Timer then
control.enabled = false
End if
Next Control
To then re-enable the timers call this procedure in the key up event.
Public Sub EnableTimers()
For each Control in Form1.controls
If TypeOf Control Is Timer then
control.enabled = true
End if
Next Control
Hope this works if you have probs with it mail me at [email protected] .....I'll be glad to help, I have made a game making heavy use of timers before..I know it can get quite hassling. Enjoy.
-
Nov 1st, 2000, 12:31 PM
#5
Frenzied Member
I don't think that'll work, because if you have a timer with a interval like 1 minute, and the timer was at 58 seconds completed, when you disable and enable the Timer again and you'll get a huge delay.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 1st, 2000, 01:02 PM
#6
New Member
The delay would only be a couple of milliseconds though.Ok post some more code up and I'll suggest some other idea.Tomorrow.I just need to see exactly what you want your app to do.
-
Nov 1st, 2000, 02:59 PM
#7
Hyperactive Member
Try this:
Code:
If KeyAscii = 65 Or KeyAscii = 97 Then
MsgBox "you pressed a!"
End If
-
Nov 1st, 2000, 03:06 PM
#8
Hyperactive Member
You really must post code!
You can't be helped unless you show us your code. Two other things you could try:
1. Set the forms keypreview to true
2. If you have an intensive loop running somewhere add a DoEvents in it. This will allow the keypress procedure to run
Two simple methods
-
Nov 2nd, 2000, 10:39 AM
#9
Thread Starter
Junior Member
Ok, here is some code
This is what I want to do:
This is a two person trivia game where a question is displayed then the counter counts down from 10 ( the first person that rings in (presses A for player 1 and L for player 2) will be prompted to enter the correct answer.
Here is the code for the timer:
Amount = Val(lbltimer.Caption)
If Amount = 0 Then
Timer1.Enabled = False
Else
Amount = Amount - 1
lbltimer.Caption = Str$(Amount)
End If
'when enabled this timer counts down from 10
If lbltimer.Caption = 0 Then
lblquestion.Caption = "Time's Up"
End If
If Val(lbltimer.Caption) >= 1 Then
keypressaq
End If
now sometime during this counter is counting down, a user that knows the correct answer would press either A or L (depending on whether they are player 1 or 2)
All i need now is how to put in the code that will make the answer form show when the user presses there ring-in button.
Thanks.
Drew
-
Nov 2nd, 2000, 11:55 AM
#10
Frenzied Member
I don't see your problem man, this code works for me, give it a try:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If UCase(KeyCode) = vbKeyA Then
MsgBox "You pressed A!"
Timer1.Enabled = False
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "10"
KeyPreview = True
End Sub
Private Sub Timer1_Timer()
Amount = Val(Label1.Caption)
If Amount = 0 Then
Timer1.Enabled = False
Else
Amount = Amount - 1
Label1.Caption = Str$(Amount)
End If
'If Val(Label1.Caption) >= 1 Then
'keypressaq
'End If
End Sub
Just put a label and a timer on your form and run it!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|