Author |
Message |
CodeMonkey2000
|
Posted: Mon Oct 29, 2007 5:06 pm Post subject: How do I poll events? Or at least take multiple keydown evets at once? |
|
|
My problem is that vb only recognizes that only one key is being pressed at a time. How do I allow for multiple key presses?
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon Oct 29, 2007 5:55 pm Post subject: RE:How do I poll events? Or at least take multiple keydown evets at once? |
|
|
You could possibly build up a queue for the key strokes, and read input from there.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
CodeMonkey2000
|
Posted: Tue Oct 30, 2007 3:13 pm Post subject: RE:How do I poll events? Or at least take multiple keydown evets at once? |
|
|
And how do I do that?
|
|
|
|
|
|
cool dude
|
Posted: Thu Nov 01, 2007 9:43 am Post subject: Re: How do I poll events? Or at least take multiple keydown evets at once? |
|
|
I programmed this a long time ago. here is a little example where u can press multiple keys.
Description: |
|
Download |
Filename: |
FIGHT_~1.FRM |
Filesize: |
1.93 KB |
Downloaded: |
150 Time(s) |
|
|
|
|
|
|
Brightguy
|
Posted: Thu Nov 01, 2007 2:46 pm Post subject: Re: How do I poll events? Or at least take multiple keydown evets at once? |
|
|
Er, that's not yours.
Anyway, that method is not completely reliable since a form only receives KeyDown and KeyUp events when it has the focus. An alternative is to use GetKeyboardState instead, so for example you would do:
VisualBASIC: | Private keys(256) As Byte
Private Declare Function GetKeyboardState Lib "user32.dll" (pbKeyState As Byte) As Long
Private Sub Timer1_Timer()
GetKeyboardState keys(0)
If keys(vbKeyUp) And &H80 Then guy1.Top = guy1.Top - 60
If keys(vbKeyDown) And &H80 Then guy1.Top = guy1.Top + 60
If keys(vbKeyRight) And &H80 Then guy1.Left = guy1.Left + 60
If keys(vbKeyLeft) And &H80 Then guy1.Left = guy1.Left - 60
End Sub |
|
|
|
|
|
|
MIdas0036
|
Posted: Thu Dec 20, 2007 9:53 am Post subject: Re: How do I poll events? Or at least take multiple keydown evets at once? |
|
|
this is something i program this aloang time ago to lock my computer while i am out of class and it has the same keypress function that you are asking about but easy to code
Description: |
|
Download |
Filename: |
LOCK.zip |
Filesize: |
241.83 KB |
Downloaded: |
134 Time(s) |
|
|
|
|
|
|
CodeMonkey2000
|
Posted: Thu Dec 27, 2007 2:53 pm Post subject: RE:How do I poll events? Or at least take multiple keydown evets at once? |
|
|
What does &H80 mean?
|
|
|
|
|
|
OneOffDriveByPoster
|
Posted: Thu Dec 27, 2007 9:55 pm Post subject: Re: RE:How do I poll events? Or at least take multiple keydown evets at once? |
|
|
CodeMonkey2000 @ Thu Dec 27, 2007 2:53 pm wrote: What does &H80 mean? It's VB notation for hexadecimal. &H80 is 0x80 is (in binary: )1000 0000.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
CodeMonkey2000
|
Posted: Thu Dec 27, 2007 11:41 pm Post subject: RE:How do I poll events? Or at least take multiple keydown evets at once? |
|
|
In the if statement in the code above what is the &H80 checking?
|
|
|
|
|
|
OneOffDriveByPoster
|
Posted: Fri Dec 28, 2007 9:47 am Post subject: Re: RE:How do I poll events? Or at least take multiple keydown evets at once? |
|
|
CodeMonkey2000 @ Thu Dec 27, 2007 11:41 pm wrote: In the if statement in the code above what is the &H80 checking? Well as previously posted, 0x80 is 1000 0000. So using the bitwise-and with 0x80 (on a byte) checks if the high-order bit is set (i.e. 1). GetKeyboardState() changes the array to reflect the status of keys. "If the high-order bit is 1, the key is down; otherwise, it is up." (from MSDN)
|
|
|
|
|
|
|