|
-
Jun 1st, 2002, 09:48 PM
#1
Thread Starter
Lively Member
Better key detection
Whats a good way to detect key presses? Using things like if KeyCode = vbKeyDown Then leaves this annoying little delay between pressing the key and doing stuff.
Last edited by Drakon; Jun 1st, 2002 at 10:36 PM.
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 2nd, 2002, 12:38 AM
#2
I find that the easiest way is to keep an array of booleans, like so:
Code:
Public keys(256) as Boolean
Private Sub Form_KeyDown(keyAscii As Integer)
keys(keyAscii) = True
End Sub
Private Sub Form_KeyUp(keyAscii As Integer)
keys(keyAscii) = False
End Sub
Private Sub DoKeys()
If keys(...) Then
'... do stuff
End If
End Sub
Just call DoKeys at each iteration of your main loop.
Z.
-
Jun 2nd, 2002, 07:07 AM
#3
Thread Starter
Lively Member
Where can I find a list of the key's ascii numbers?
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 2nd, 2002, 07:17 AM
#4
Frenzied Member
there is constants called
vbKeyA for example...
I would rather use getkeystate though...
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 2nd, 2002, 08:14 AM
#5
Thread Starter
Lively Member
how do I use getkeystate?
and I get an error when I use only keyAscii as Integer in the parentheses after Private Sub Form_KeyUp and KeyDown.
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 2nd, 2002, 08:59 AM
#6
Frenzied Member
VB Code:
If GetKeyState(vbKeyA) <> 1 Then Form1.Caption = "Key a pressed"
but that code is not supposed to go into a key down event or something, but needs to be put in a loop!
Sanity is a full time job
Puh das war harter Stoff!
-
Jun 2nd, 2002, 12:02 PM
#7
Thread Starter
Lively Member
I have a feeling I did something wrong somewhere... The program starts and it instantly does the code in the GetKeyState thing.
Where is GetKeyState declared, and as what?
Last edited by Drakon; Jun 2nd, 2002 at 01:21 PM.
Do you know if you will answer no to this question?
If we've never seen something happen, we can't know if its impossible.
If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
If someone orders you to disobey all of their orders, do you obey or disobey?
-
Jun 2nd, 2002, 03:02 PM
#8
Originally posted by Drakon
and I get an error when I use only keyAscii as Integer in the parentheses after Private Sub Form_KeyUp and KeyDown.
There are probably other parameters that I dont remember. The code I posted was off the top of my head.
Z.
-
Jun 2nd, 2002, 06:47 PM
#9
Addicted Member
getkeystate will return a non zero value if the key was pressed any time before the previous call to getkeystate. What I usually do is run through a loop of all the keys 1 to 255 with getkeystate when my prog starts, this will then void any key presses prior to program execution and later on during the application.
Who needs rhetorical questions anyway?
Bazza NET - The place you want to be!

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
|