p_dog_2007 Posted March 2, 2004 Posted March 2, 2004 If i want 2 guys on the screen that walk around by keys, how can i make both of them walk at the same time? It only capures 1 key at a time, I've tried getasynckeystate but it wont work??? thanks Quote
kas Posted March 2, 2004 Posted March 2, 2004 Do you mean that you want the same key press to affect both guys' movement; or that every alternate key affects each of them in turn? Quote
p_dog_2007 Posted March 2, 2004 Author Posted March 2, 2004 they move with different keys, like one with the arrow and the other with w, s, d, and a, but if I press over on one and on the other at the same time, onlu one will move. I need to capure all the key presses Quote
kas Posted March 2, 2004 Posted March 2, 2004 Well, AFAIK the system can only process one keypress at a time, but the delay time is very, very small so effectively it seems to the user that they are simultaneously pressing and their instructions are being processed. To test this theory (maybe to explain it better :-{ ) try this test. In Notepad (or even in a Reply Box in this forum) try pressing any two alphabetical keys simultaneously. You should see that both letters pressed will be displayed one after the other on the page/in the box. The order being decided by which was minimally pressed before the other. I know that Control and Shift keys are dealt with slightly differently, but I didn't think the arrow keys were. Presumably, you are using something like KeyPreview in a form and analyzing the keydown value? Quote
p_dog_2007 Posted March 2, 2004 Author Posted March 2, 2004 but for the guy to walk, you press and hold the key until you getto whare u ant to go. would DirectX be able to do 2 or more keys at the same time? Quote
TechnoTone Posted March 3, 2004 Posted March 3, 2004 Using the KeyDown and KeyUp events you can determine what keys are being held down at any particular time. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
*Experts* mutant Posted March 3, 2004 *Experts* Posted March 3, 2004 would DirectX be able to do 2 or more keys at the same time? Yes as far as I know. Quote
Leaders Iceplug Posted March 3, 2004 Leaders Posted March 3, 2004 I can't see how GetAsyncKeyState "wont work"... unless you did it incorrectly. You may also be able to have some boolean variables in your form declaration and let them be True when you have detected the KeyDown, and False when the KeyUp is detected. In a timer or a loop, you can do the movements. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
TechnoTone Posted March 4, 2004 Posted March 4, 2004 Hello? What's wrong with KeyDown and KeyUp? I've tested it and it works. You can press as many keys simultaneously as you like and keep track of which ones are down and which are not. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
p_dog_2007 Posted March 4, 2004 Author Posted March 4, 2004 not if you want to hold 2 keys at the same time Quote
ballisticnylon Posted March 5, 2004 Posted March 5, 2004 Hello? What's wrong with KeyDown and KeyUp? I've tested it and it works. You can press as many keys simultaneously as you like and keep track of which ones are down and which are not. I must be missing something. Take this code for example: Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown Debug.Write(e.KeyData.ToString) End Sub Now lets say I press and hold 'Q'. The debug window fills in with 'Q"s. Now let's say that, while still holding down 'Q', I press and hold down 'W'. Our debug window starts writing 'W''s instead of 'Q''s. The event arguments for the KeyDown event only tell us about the 'W'. And now when I release the 'W' key, the event stops firing altogether, even though I'm still holding down 'Q'. Cool avatar, btw. Quote "It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve." - Edgar Allan Poe, 1841 I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker. - Helen Keller
TechnoTone Posted March 5, 2004 Posted March 5, 2004 You have to use both KeyDown and KeyUp. Lets say "W" is a key you want to monitor. Dim wKeyState as Boolean Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.W Then wKeyDown = True End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp If e.KeyCode = Keys.W Then wKeyDown = False End Sub Now, you can test the value of wKeyDown to see whether the "W" key is currently being held down. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
ballisticnylon Posted March 5, 2004 Posted March 5, 2004 Cool. And it works for multiple keys, like you said: Dim WKeydown As Boolean Dim QKeyDown As Boolean Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyData = Keys.W Then WKeydown = True If e.KeyData = Keys.Q Then QKeyDown = True RefreshLabels() End Sub Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp If e.KeyData = Keys.W Then WKeydown = False If e.KeyData = Keys.Q Then QKeyDown = False RefreshLabels() End Sub Sub RefreshLabels() If WKeydown Then lblW.Text = "W" Else lblW.Text = "" If QKeyDown Then lblQ.Text = "Q" Else lblQ.Text = "" End Sub Thanks for the trick. Quote "It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve." - Edgar Allan Poe, 1841 I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker. - Helen Keller
Hamburger1984 Posted March 5, 2004 Posted March 5, 2004 here's one possible solution to the problem.... hope this helps! see attachment :rolleyes: :D Andreaskeydownproblems.zip Quote
TechnoTone Posted March 5, 2004 Posted March 5, 2004 Nice solution there Andreas. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.