Thread: eventkeyargs e

  1. #1
    Registered User
    Join Date
    Oct 2008

    eventkeyargs e

    hi again

    i am using the 'KeyDown' event to monitor the keyboard.
    whilst the same key is held down the program with react properly by moving the object in the required direction.

    if i then press another key whilst keeping the original held down,

    (for example - hold the right arrow down, then without releasing the right arrow i also tap the space bar.)

    the keyeventargs accepts the fact the space has been pressed but ignores that the right key is still down and stops processing it ??

    the process will not continue until the key is released and pressed again.

    is there a better way to check this? should i override the key handler ?

    if this does not make sense please post and i will try to clarify a little more.


  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    It doesn't very much. Clarify this: what do you want to do? That is easier to answer than what is actually happening

    edit: trying a bit the KeyDown event handler, I see that it doesn't really matter when you hold a key pressed. This is what I get if you want to simulate an ALT+F4
    1) You have a keyDown event. You have a variable that is like AltPressed. Whn you press ALT it is set to true. When it is set true and another variable F4Pressed is true then you can do whatever you want.
    2) You will have a KeyUp event handler (haven't tried it though), so when ALT is reales AltPressed will become false
    Last edited by C_ntua; 11-04-2008 at 07:52 AM.

  3. #3
    Registered User
    Join Date
    Oct 2008
    ok sorry if i wasnt clear.

    its basically game code i am writing.

    i have a graphic which i can move left and right ( the key will autorepeat if i hold it down and is caught by the eventkeyargs without problem)

    i now want to add a jump to this movement.

    so while moving either left or right, i want to be able to press the space bar to jump.

    when i press space it is effectively cancelling the fact that the left or right key is still down and will not move again until either key is released and repressed.

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    In your game loop (you should have one) you should be checking to see the state of your character (if he's jumping, moving, etc.).

    When you hit the space key, set the state to jumping, set a starting point, and in your game loop if you're jumping then do the physics for that jump (moving x, y, z etc.). If the character is under the max height, move him up, if he's over, move him down, and when he hits the ground turn off the jumping state.

    When you hit left or right, move the character left or right. It should carry over even if he's jumping, swimming, whatever because it's completely independent (unless you say otherwise).
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    Registered User
    Join Date
    Oct 2008
    thanks for the reply.

    I am not actually utilising a game loop at the moment as i am just trying different things to see if i can get them to work.

    My next step is to actually split the current code i have into seperate classes and make sure all variables etc can be seen from the main code ( which will be my game loop).

    i have the move - jump - redraw code sorted out but it is still very linear, as that is how i learnt to program a long time ago.

Popular pages Recent additions subscribe to a feed