Results 1 to 4 of 4

Thread: Multiple Key Presses

  1. #1

    Default Multiple Key Presses

    Hello,

    I need help with handling multiple key presses for my platformer. I've looked in the example 'Input' project, and maybe I've missed it because I have had this problem for a while now, but haven't quite gotten it yet so I decided to ask for help.

    My situation is that I want to press the 'A' or 'D' key to move left or right respectively and then press 'W' to jump or 'Shift' to increase running speed. I only have one slot connected by the following:

    Code:
    slots.connect(window.get_ic().get_keyboard().sig_key_down(), this, &AnimateImage::KeyInput);
    The function 'KeyInput' of course checks by if conditions and go from there. But if holding down 'D' and then I press 'W', it cancels my 'D' movement so then I only jump while loosing speed. Is there another way to go about this, should I set bools to true if key down and false on key release, or is there something I am missing?

    Thanks everyone

  2. #2

    Default

    ClanLib's input manager executes the callback for every key you push down and release. When you press down two keys at the same time, the callback will be executed twice for each of the keys. What I would do is make a class that registers what inputs is being pressed down (through ClanLib calling a function in that class), and then have the rest of the game code read from that class to decide what to do. The class would have something like std::map<KeyCode, KeyStatus> that maps a keycode to it's status (pressed or not pressed).

  3. #3
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    You can also use polling:

    if(keyboard.get_keycode(clan::KEY_D)) ...

    More info at http://clanlib.org/documentation/3.0/UserInput.html

  4. #4

    Default

    Alrighty, I will consider which approach would be the best and design my code from there.

    Thanks for the help and ideas!

Similar Threads

  1. Multiple Stacks of 200
    By I-Am-Legend in forum Suggestion Box
    Replies: 1
    Last Post: 09-11-2013, 11:14 PM
  2. should we have multiple teams
    By ducktape in forum Tanked
    Replies: 3
    Last Post: 04-15-2012, 03:43 AM
  3. How do I use multiple mice?
    By manxx in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 12-09-2009, 06:23 PM
  4. mouse presses on two windows?
    By babyvegas in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-30-2008, 08:41 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •