Simulating KeyUp Event
-
Is there a way using .NET C++ to simulate a key being "un-pressed"? Basically, I am making a video game, and when a key is pressed (say the right arrow) and then the press the space bar to jump, while still holding the right arrow, the space bar key will be read, but the right arrow key wont be, even though its still being pressed. Is there a way to get around this? Thank you. Mike
-
Is there a way using .NET C++ to simulate a key being "un-pressed"? Basically, I am making a video game, and when a key is pressed (say the right arrow) and then the press the space bar to jump, while still holding the right arrow, the space bar key will be read, but the right arrow key wont be, even though its still being pressed. Is there a way to get around this? Thank you. Mike
You could use "KeyDown" and "KeyUp" respectively. Treat every key pressed (KeyDown event) as active until you receive a KeyUp event. You would only need to do so for a few selected keys (plus mouse buttons) and not for any key that does something special (thought you might want to stick with KeyDown there as well). Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
You could use "KeyDown" and "KeyUp" respectively. Treat every key pressed (KeyDown event) as active until you receive a KeyUp event. You would only need to do so for a few selected keys (plus mouse buttons) and not for any key that does something special (thought you might want to stick with KeyDown there as well). Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
Thank you very much, that solution works. I actually had another question. I wanted to be able to call a function multiple times during the existance of the program. I thought about using a clock, however if a key is pressed, the clock is interrupted. Is there anyway, using Threading, or Threading::Timers or some other method, to call a function. Basically, I want to be able to have my character jump, and I don't know how to do something like while(in_the_air){ make character fall }.
-
Thank you very much, that solution works. I actually had another question. I wanted to be able to call a function multiple times during the existance of the program. I thought about using a clock, however if a key is pressed, the clock is interrupted. Is there anyway, using Threading, or Threading::Timers or some other method, to call a function. Basically, I want to be able to have my character jump, and I don't know how to do something like while(in_the_air){ make character fall }.
Well, if you have a 2D-Game, its quite "easy": simply have a rectangle around your players legs and if the bottom is adjacent to the ground he does not fall. Otherwise simply accelerate him downwards. Or move the scenery upwards ;) Another approach would be to have a black/white representation of your level. White would be "empty" and Black would be "filled with scenery". >You would then define some "key points" of your player character. If one of those points touches "black", you have a collision with the scenery. Cheers Sebastian Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.