LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2009, 08:37 AM   #1
FinalRebel
Member
 
Registered: Aug 2009
Posts: 31

Rep: Reputation: 15
get the value of keys


hi
i'm writing asmall game
and i need to get the value of keys and store it in some variables
my compiler doesn't provide kbhit() and getc()
is there another way.
 
Old 09-19-2009, 10:30 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
kbhit() and getc() are both Borland-C proprietary function calls; you will only find them in Borland compilers.

If you are writing a text-driven game (i.e. the user is typing things in), then you would probably be best off looking at the GNU readline library: http://tiswww.case.edu/php/chet/readline/rltop.html which is non-standard but very portable. But that only works with lines of text, not individual keystrokes. You could also use standard C functions (fgets() using stdin as the input stream).

The standard UNIX way to detect a single keystroke is to set the terminal into non-canonical mode, setting the input stream as non-blocking, and either select() or poll() for a new keystroke or register an interrupt handler callback. See http://en.wikibooks.org/wiki/Serial_Programming/termios

However, termios can be complicated and unforgiving, so you may want to look at the ncurses library (http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/) for a more convenient way of handling a terminal.

If you are using a graphical (X) environment, then you will probably want to look at the SDL library instead (http://lazyfoo.net/SDL_tutorials/lesson08/index.php) which provides cross-platform support for various hardware access, including the keyboard.

Hope that helps,

–Robert J Lee
 
Old 09-19-2009, 10:59 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
http://www.linuxquestions.org/questi...9/kbhit-34027/
http://www.linuxquestions.org/questi...d-in-c-150067/
 
Old 09-20-2009, 05:04 AM   #4
FinalRebel
Member
 
Registered: Aug 2009
Posts: 31

Original Poster
Rep: Reputation: 15
thanks for help
 
Old 09-20-2009, 06:44 AM   #5
giftlftr_23
Member
 
Registered: Oct 2008
Location: I live where I'm currently standing on
Distribution: fedora, opensuse
Posts: 34

Rep: Reputation: 17
SDL will greatly help you in developing your small game since it has almost complete library for interaction with I/O(monitor, mouse, keyboard etc..)
 
Old 09-21-2009, 12:33 AM   #6
FinalRebel
Member
 
Registered: Aug 2009
Posts: 31

Original Poster
Rep: Reputation: 15
is there a good books to learn make games in console application
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mouse keys as modifier keys (ctrl & alt) belda Linux - Desktop 3 06-25-2009 10:37 AM
USB keyboard function keys/numeric keys on boot raypen Linux - Hardware 4 04-17-2008 03:07 PM
Keys in bind -p or inputrc, what do these keys translate to? muha Linux - Newbie 0 03-06-2006 06:52 AM
with keys is the keys that change languages? AKAKAK Fedora 2 01-25-2005 10:11 AM
Configuring SSH to accept only keys (already have keys) fr0st Linux - Security 3 11-04-2003 03:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration