|
-
Aug 30th, 2001, 09:16 AM
#1
Problems with arrowkeys
Hi,
I'm using the arrowkeys to give steering commands to a moving object. I'm using the GetAsyncKeyState API. These commands are working well.
But the commands do have a "nasty" side-effect, while using an arrow key the focus for the other control on the FORM is changing along ther direction of the arrowkey. If only the focus would be changing, the problem would be negletable, but when moving along an Option-Control the selected Option is changed, THAT is "nasty". Does anyone know a way around that. By the way, the quick solution to use other keys for the steering, is not really what I'm looking for.
Thanks
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Aug 30th, 2001, 07:30 PM
#2
Junior Member
I ve been checking the api and it seems to me you have 2 options.
1) Make an Keyboard Hook to intercept specific keys (in this case the arrow keys) and delete them and then do youu own moving routine.. Well that is some pretty dificult stuff...=)
2) I Suggest you use this Code, and call ResetLastFocus every time your GetAsyncKeyState Api monitors an arrow key
Option Explicit
Dim LastInputControl as Variant
Private Sub Timer1_Timer()
Set LastInputControl=Me.ActiveControl
end sub
Private ResetLastFocus()
LastInputControl=Control.SetFocus
end sub
I havent Debuged this much but it Should Work... Please let me now how it goes
-
Aug 31st, 2001, 01:10 AM
#3
Thank's Thanathos
I will check your code, but the answer will have to wait 'til next week, I'm on my way home. (TGIF ;-) ) I'll check it on Monday.
Greetings to the Caribic
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 3rd, 2001, 03:02 PM
#4
Hi Thanathos;
just tried your solution
I had to modify it a bit, anyhow it doesn't work. I haven't found the solution to reset the focus to the LastInputControl (I used just a fixed control) after the arrowkey is pressed.
Code:
Private Sub Timer2_Timer()
LastInputControl = Me.ActiveControl.Caption
If (GetAsyncKeyState(vbKeyLeft)) Then
' turn left
TurnIndicator.Value = TurnIndicator.Value - 1
ElseIf (GetAsyncKeyState(vbKeyRight)) Then
' turn right
TurnIndicator.Value = TurnIndicator.Value + 1
End If
If (GetAsyncKeyState(vbKeyUp)) And SpeedIndicator.Value > 0 Then
' Speed up
SpeedIndicator.Value = SpeedIndicator.Value - 2
ElseIf (GetAsyncKeyState(vbKeyDown)) And SpeedIndicator.Value < (LfzMaxSpeed - LfzMinSpeed) Then
' Speed down
SpeedIndicator.Value = SpeedIndicator.Value + 2
End If
Me.Marker2Drop.SetFocus
End Sub
Anyhow the press of an arrowkey still moves the focus around, afterwards the focus is set to the selected control (Marker2Drop).
It seems that the use of the arrowkey is directly moving the focus.
So I'm still searching
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 4th, 2001, 03:42 AM
#5
Retired VBF Adm1nistrator
I myself use the normal Form events for key presses.
When the user presses a key, I set a particular public boolean value true.
Then each time the game screen is being updated it does whatever it has to do with the key in that state, and then resets the value.
Take a look in the craft code for an example.
You'd wanna look at the Form_Key* events for the main form, and also the main game loop in there too.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 4th, 2001, 12:55 PM
#6
-
Sep 5th, 2001, 02:16 AM
#7
Retired VBF Adm1nistrator
Well focus should only be shifted if a control currently has focus.
Give the form itself focus, and also remove the TabIndex property of all the controls.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 5th, 2001, 09:50 AM
#8
??
Remove TabIndexProperty (whow do I do that), or only TabStop=false? The latter doesn't do it!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 5th, 2001, 10:09 AM
#9
Retired VBF Adm1nistrator
Right neither of those will work.
Okay, if you add a picturebox to the form.
Display the game in the picturebox, and give it focus.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 5th, 2001, 10:19 AM
#10
OKay, I do have a picturebox in my form. If I give it the focus just before checking the Arrowkeys, the problem concerning the shifted options is gone (Thanks).
The sideeefect is that I'm now not able to make any input into textboxes, 'cause the focus will be lost. Maybe I have to stop the Timer2 during the time a textbox has the focus???? Just thinking loud.
I'll try my very best, Miss Sophie!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 5th, 2001, 10:22 AM
#11
Retired VBF Adm1nistrator
I'd try to avoid using the textboxes if possible...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 5th, 2001, 12:28 PM
#12
-
Sep 8th, 2001, 02:45 PM
#13
Frenzied Member
my program is not really a game, it's of a training tool for some submarine hunting tactics
Sorry, I'm just curious about that part 
Submarine hunting tactics? REAL submarines, like a training program for the navy or something?
-
Sep 9th, 2001, 10:45 AM
#14
O.K. here is a short description:
The application is made to train in the use of "Dopplerinformation" to locate a submarine. In order to make that possible the sub must produce a stable frequency which the searcher can detect on selectable locations. The change in the frequency, due to the Doppler-Phenomena, enables the searcher to locate the sub without nay other information.
In the application the searcher can select the positions where he wants to listen and also gets the frequency-information of those locations. I my special case the searcher is an aircraft (steering only for left/right and speed up/down), the sensor are socalled buoys, the frequency-informations is given on Frequency-Time indicators (Frequency horizontal, time verticaly given a picture of the actual and history information).
There is no fancy visualisation, since no real pictures of aircraft nor submarines are needed. So no real "game", the clou only comes to those who learned such tactics and who wanted to keep trained in the use of them.
It's not used by the "navy" (yet??), I'm working on it.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 9th, 2001, 02:07 PM
#15
Retired VBF Adm1nistrator
Do you have to kill us now ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 10th, 2001, 10:32 AM
#16
Frenzied Member
Opus, that seems really cool, but I don't think the navy will make it official unless you know some people there, or you're in the navy
-
Sep 10th, 2001, 12:54 PM
#17
Jotaf98, something makes me think you're a student ;-)
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 10th, 2001, 01:38 PM
#18
Thanks plenderj,
the GetTickcount is controlling it now, using a setting of 500 (millisecs), the normal click_events are not blocked and the steering comands work as desired. However, there is a small problem, if I close the application no using the X in the right hand corner I get a runtime-error 5 at the line where the focus is set to a picturebox. This is not happening when closing normally via an end command.?????
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 11th, 2001, 01:05 AM
#19
Retired VBF Adm1nistrator
Well it could be due to the fact that the loop is still runnning even though the form is unloading.
So if you do something like this :
VB Code:
Do While DoLoop
DoEvents
If (GetTickCount() - LastTick) >= 500 Then
LastTick = GetTickCount()
'your code here
End If
Loop
Then when you're going to be unloading the form for whatever reason, set DoLoop = False
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 11th, 2001, 02:59 AM
#20
Okay, but whre do I have to put code that is supposed to be used in case of the click on the "X" of the MainForm. That "X" just closes the form. Or is there an event Unload?
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 11th, 2001, 03:13 AM
#21
Retired VBF Adm1nistrator
VB Code:
Option Explicit
Private closedByApp As Boolean
Private Sub Command1_Click()
closedByApp = True
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not closedByApp Then MsgBox "Someone clicked the x !"
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 11th, 2001, 06:48 PM
#22
-
Sep 12th, 2001, 01:09 AM
#23
Retired VBF Adm1nistrator
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 12th, 2001, 06:05 PM
#24
Frenzied Member
-
Sep 12th, 2001, 11:53 PM
#25
-
Sep 13th, 2001, 02:02 AM
#26
Retired VBF Adm1nistrator
No problem, just leave the cheque on the way out.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 14th, 2001, 05:07 PM
#27
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
|