LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-22-2007, 09:57 AM   #1
neoAKiRAz
Member
 
Registered: Jan 2006
Location: Uruguay
Distribution: Kubuntu
Posts: 48

Rep: Reputation: 15
Any advanced keyboard handling API for console?


Hi, I need the functionality provided with man graphic APIs, like SDL and OpenGL, in which one waits for events from the keyboard and is able to check the status of some particular key with something like KEY_UP or KEY_DOWN.

I won't be needing a graphical window. I just need to write a program which will be used to control a mobile robot (over a radio link) using the arrow keys in the keyboard in the fashion of car driving games (need for speed, colin mcrae). Is there a simple library, instead of SDL or OpenGL, which could be used to do this from a simple terminal window? The ncurses library offered a great improvement in keyboard handling, but it wasn't enough. Hope someone can help

Thanks!
 
Old 10-23-2007, 04:31 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
What you are looking for is the "ncurses" library.
http://www.google.nl/search?q=ncurses+tutorial
 
Old 10-24-2007, 11:35 AM   #3
neoAKiRAz
Member
 
Registered: Jan 2006
Location: Uruguay
Distribution: Kubuntu
Posts: 48

Original Poster
Rep: Reputation: 15
Thanks, but I've already tried it. My mistake for saying KEY_UP and KEY_DOWN, which are actual keys in ncurses...

What I really need is to receive key press and release events, but I don't think this can be done with ncurses... At least I haven't realized how to do it yet. I found though something about putting the keyboard in RAW mode, so that I'm then able to do what I want. I haven't tried it yet:

http://listas.hispalinux.es/pipermai...er/000442.html

Let's see if it does the job. Greetz!
 
Old 10-26-2007, 02:04 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Google 'non-blocking character-at-a-time terminal IO' or search these forums for 'getch'.
--- rod.
 
Old 10-27-2007, 12:39 AM   #5
neoAKiRAz
Member
 
Registered: Jan 2006
Location: Uruguay
Distribution: Kubuntu
Posts: 48

Original Poster
Rep: Reputation: 15
I've tried that, but no I doesn't suits me either. I'll explain:

The problem with that is that if I press for example X and hold it I start reading a stream of x characters, but if, while still holding it, I press Z then the stream of x stop and a stream of z begins, so I don't know if the user is still pressing x.

I realized that I have no other choice than to be able to receive the press and release key events. I found googling that there's a way to put the keyboard in "RAW" mode using fnctl so that I could recive a code indicating the key and the event (press, release), although I couldn't make it work with the (very little) documentation I found.

I also realized that even if I managed to code it, I would end up with my own implementation of the same functionality that libraries like SDL already provide, and it would be kind of a waste of time. So I the end I sticked to SDL

Greetz!
 
  


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
Different way of handling keyboard entries by Linux compared to WIndows? gommans Linux - Hardware 0 02-19-2007 06:44 AM
Looking for cross platform Input API (mouse, joystick, keyboard) Omni Programming 3 11-01-2006 07:17 PM
No Keyboard/Mouse in X/Console Diademed Linux - Newbie 2 09-19-2004 02:28 PM
Cannot Use Keyboard Under Console!! stelmed Slackware 8 06-11-2004 08:14 AM
API handling KaktusKnight Linux - General 0 03-14-2003 06:25 AM

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

All times are GMT -5. The time now is 10:15 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