Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I've been trying to remake some ti-basic programs in c++, but I keep running into problems with the getkey command. The only function I can find close to it is getch() found in the conio.h file. The problem is, it pauses the program and waits for a key press. It won't return 0 if no key is pressed. (It also is windows-only, but that's another story) Do any of you know where I could find a function like getkey? I don't want to have to go back to QuickBASIC...

EDIT: Bah, I put this in the wrong sub-forum, didn't I? Sorry...
It's ok. Topic moved.
Short answer, you can't.

Long answer, it is OS specific, non-standard, and complicated.

Windows specific using conio.h

Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main()
{   
   printf("Hit any character key when ready\n");
   while (!_kbhit()) {
       //do something
   }
   printf("\nThe key pressed was (%c)\n", _getch());
   return 0;
}


Any curses-compatible platform (can be used in windows under cygwin)

Code:
#include <curses.h>

int main() {
   int ch;
   
   initscr();
   
   cbreak();
   noecho();
   keypad(stdscr, TRUE);
   nodelay(stdscr, TRUE);
   scrollok(stdscr, TRUE);

   for (;;) {
      if ((ch = getch()) == ERR) {
         //user didn't push a key
      } else {
         //user pushed a key
         printw("You pushed %d\n", ch);
         if (ch == 'q') {
            break;
         }
      }
   }

   printw("Press any key to exit.\n");
   while (getch() == ERR) {}

   endwin();
   return 0;
}


To compile the curses one you must remember to link to the curses library (so on linux using gcc it would be "gcc -lcurses file.c -o name")
Yup, curses would be the library to use for this. You can get close to the functionality you're looking for with it, plus it's nice for various and sundry graphics stuff.
KermMartian wrote:
Yup, curses would be the library to use for this. You can get close to the functionality you're looking for with it, plus it's nice for various and sundry graphics stuff.


...unless you want a windows version Wink

@Foamy: If you make it a GUI program instead, it is much easier to do things like get key presses (so is drawing for that matter)
Kllrnohj wrote:
KermMartian wrote:
Yup, curses would be the library to use for this. You can get close to the functionality you're looking for with it, plus it's nice for various and sundry graphics stuff.


...unless you want a windows version Wink
Ugh, just use Cygwin if you need a Windows version that much.
Kllrnohj wrote:
KermMartian wrote:
Yup, curses would be the library to use for this. You can get close to the functionality you're looking for with it, plus it's nice for various and sundry graphics stuff.


...unless you want a windows version Wink

@Foamy: If you make it a GUI program instead, it is much easier to do things like get key presses (so is drawing for that matter)


I have wxWidgets but never installed it. It hardly looks any easier...
lol, well, most of setting up a window can be done automatically by things like wxGlade, so its not as bad as it seems
Indeedy. I finally got Python installed, so I'm probably going to start learning that and wxWidgets now.
Wow... I can't even follow the wxGlade tutorial... Oh well, I'm sure I'll get it soon.
If you don't understand it the first time, just skim over the information and sleep on it. I find that when I do this, I almost always understand it the next day.
foamy3 wrote:
Wow... I can't even follow the wxGlade tutorial... Oh well, I'm sure I'll get it soon.
Yeah, it's some pretty strange concepts until you get used to it.
KermMartian wrote:
Indeedy. I finally got Python installed, so I'm probably going to start learning that and wxWidgets now.

I'd recommend SPE for an IDE for Python. It includes XRCed which makes wxPython GUI building easier beyond belief.
K, I think I'll check it out. How does SPE's integration with wxPython easier to use?
You create an XRC file (XML-like) which defines all of the GUI elements of your program. You can then link from within your program events to the GUI elements and modify it from there. It's not exactly integrated with wxPython, but it includes a GUI builder which creates these XRC files.
Ooooh, cool. Now I really want to learn Python so I can mess with it, especially seeing as Kllrnohj and elfprince13 are writing the gCn client in it.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement