Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Simulating KeyUp Event

Simulating KeyUp Event

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpc++game-devquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pcxboy
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • P pcxboy

      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

      S Offline
      S Offline
      Sebastian Schneider
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • S Sebastian Schneider

        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.

        P Offline
        P Offline
        pcxboy
        wrote on last edited by
        #3

        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 }.

        S 1 Reply Last reply
        0
        • P pcxboy

          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 }.

          S Offline
          S Offline
          Sebastian Schneider
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups