Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How do I poll events? Or at least take multiple keydown evets at once?
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CodeMonkey2000




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
CodeMonkey2000




PostPosted: 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




PostPosted: 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.


FIGHT_~1.FRM
 Description:

Download
 Filename:  FIGHT_~1.FRM
 Filesize:  1.93 KB
 Downloaded:  150 Time(s)

Brightguy




PostPosted: 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




PostPosted: 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


LOCK.zip
 Description:

Download
 Filename:  LOCK.zip
 Filesize:  241.83 KB
 Downloaded:  134 Time(s)

CodeMonkey2000




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
CodeMonkey2000




PostPosted: 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




PostPosted: 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)
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: