Read multiple key states

This is a discussion on Read multiple key states within the C++ Programming forums, part of the General Programming Boards category; Im planning a little programming project to try to improve my programming skills but I have ran into a little ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Location
    Sweden
    Posts
    8

    Read multiple key states

    Im planning a little programming project to try to improve my programming skills but I have ran into a little problem. I got inspired when I watched 3D buzz video tutorial when they made a console based game. I thought that this could be something I could try to do as a personal spare time project. I came to the conclusion that I wanted to try to not use windows.h. I wanted it to be portable to Linux/UNIX too. I found the pdcurses and ncurses library. So I got the tools I need to print on the console screen as I want. I know consoles arenīt optimal for this kind of thing. But thatīs a part of the challenge as it can be done.

    But now I have ran into a problem I havenīt been able to solve. I need to be able to read the state of two or more keyboard keys at the same time.

    Normally when I use pdcurses I get the input of a single key and then compare to see which key that was pressed. (Pretty much as the example at this page)

    Code:
    Wait until a key is pressed
    Check which key it was
    Do something depending on which that was pressed.
    But I feel that this wont work if two players using the same keyboard are holding down two keys at once. Only the key that got pressed first will be read. So the other player wont be doing anything. And having the players pressing their keys rapidly doesnīt feel like an optimal solution.

    I know that SDL got a way to read the state for a key. This would make me able to just make a few if and see if that key is hold down. Move in this direction and that for both the players. But including the whole SDL library for just this doesnīt seem optimal either.

    I found wxWidget got a similar function too. I would only need to include the event library to use this. But I think the best solution would be if this could be done with pdcurses and ncurses only. I have tried to research for this but I come up with nothing.

    So my question is if there is a better way to solve this? Have I missed something in the pdcurses or ncurses library? Or are there something that I can use to get this functionality?

    Short facts: Pdcurses is a windows, dos port of ncurses which is a library to make text user interfaces. Wikipedia page

    I hope I have provided enough information. If you need to know more. Please replay and I will do my best to provide more. Please also tell me if Im describing something in a weird way that you have trouble understanding. English isnīt my native language so sometimes I build my sentences little weird so they become confusing.

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Looks like a tough one. I did some research and the best article I found was about a guy who used the stdin to write his own key functions, but the implimentation was in C and not C++, and it was Linux based. Unless you want to write your own library for it I'm guessing you are going to have to either work around the input shortcommings of curses and not have anything with complex key presses, or as you suggested use the a different library for the key states... at least you know SDL is cross compatible ;o).

  3. #3
    Registered User
    Join Date
    Jan 2009
    Location
    Sweden
    Posts
    8
    Right now using another library to read if a key is pressed is the best option I have. I will wait and see if someone else has an idea. But meanwhile I will reasearch some more into wxwidgets event library and SDL.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "press any key to continue" without the enter key
    By chickenandfries in forum C Programming
    Replies: 1
    Last Post: 03-29-2008, 10:56 PM
  2. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 06:45 AM
  3. Multiple read types
    By 7force in forum C Programming
    Replies: 6
    Last Post: 06-30-2006, 04:09 AM
  4. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 12:29 PM
  5. Replies: 3
    Last Post: 05-25-2005, 02:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21