By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,193 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,193 IT Pros & Developers. It's quick & easy.

KeyPressed function?

P: n/a
Hi!

A newbie question: How can I check, whether a key has been pressed and
take that input to perform some action? I don't want to wait for that
input (=> no Enter needed) and the input should not be displayed.

Tnx a lot

Karl
Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Karl Ebener wrote:

Hi!

A newbie question: How can I check, whether a key has been pressed and
take that input to perform some action? I don't want to wait for that
input (=> no Enter needed) and the input should not be displayed.


There is nothing in standard C++ to help you.
Mostly because standard C++ is not aware of a keyboard.
All input or output is generalized to a stream.

But that doesn't mean that it can't be done on your
specific system. All it means is that there is no
general solution. You need system specific functionality
to do that.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2

P: n/a
Hi!
There is nothing in standard C++ to help you.
Mostly because standard C++ is not aware of a keyboard.
All input or output is generalized to a stream.

But that doesn't mean that it can't be done on your
specific system. All it means is that there is no
general solution. You need system specific functionality
to do that.


Could you give me a hint for Linux systems? I looked but didn't find
anything....

Another question: Is there a way to make a function return a list?
e.g.
int[] abc() { //*returning list*}

Tnx
Karl
Jul 22 '05 #3

P: n/a
Karl Ebener wrote:
Hi!
There is nothing in standard C++ to help you.
Mostly because standard C++ is not aware of a keyboard.
All input or output is generalized to a stream.

But that doesn't mean that it can't be done on your
specific system. All it means is that there is no
general solution. You need system specific functionality
to do that.


Could you give me a hint for Linux systems? I looked but didn't find
anything....

Another question: Is there a way to make a function return a list?
e.g.
int[] abc() { //*returning list*}

You can return arrays, but doing so requires you to use new[] and
delete[] and deal with the memory management yourself.

A much better idea would be to use "vector" or "list", which are classes
provided by c++ which are much easier to deal with than plain arrays.
Look them up in any good (or even most bad) C++ books :)

Chris
Jul 22 '05 #4

P: n/a
Karl Ebener wrote:

Hi!
There is nothing in standard C++ to help you.
Mostly because standard C++ is not aware of a keyboard.
All input or output is generalized to a stream.

But that doesn't mean that it can't be done on your
specific system. All it means is that there is no
general solution. You need system specific functionality
to do that.

Could you give me a hint for Linux systems? I looked but didn't find
anything....


Sorry. I donÄt know about Linux. You should ask in a newsgroup dedicated
to Linux programming.

Another question: Is there a way to make a function return a list?
e.g.
int[] abc() { //*returning list*}


int[] is not a list.
It is the notation for an array with unknown dimensions. But
beware, in this case things are not what they seem to be. The
above is in reality a way to avoid pointer notation, nothing
more. And it cannot be used as return type.

As for a list:

#include <list>

std::list<int> foo()
{
list<int> MyList;

MyList.push_back( 5 );
MyList.push_back( 7 );

return MyList;
}

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5

P: n/a
Karl Ebener wrote:
Hi!
There is nothing in standard C++ to help you.
Mostly because standard C++ is not aware of a keyboard.
All input or output is generalized to a stream.

But that doesn't mean that it can't be done on your
specific system. All it means is that there is no
general solution. You need system specific functionality
to do that.


Could you give me a hint for Linux systems? I looked but didn't find
anything....


You can try the GNU readline library.

-Arijit
Jul 22 '05 #6

P: n/a
Karl Ebener wrote:
Could you give me a hint for Linux systems? I looked but didn't find
anything....


Most likely something in the curses library. An excellent place to
start is comp.unix.programmer.


Brian
Jul 22 '05 #7

P: n/a
Karl Ebener wrote:

How can I check, whether a key has been pressed
and take that input to perform some action?
I don't want to wait for that input (=> no Enter needed)
and the input should not be displayed.


Take a look at
The Linux Keyboard HOWTO

http://web.inet-tr.org.tr/Online/Lin...ard-HOWTO.html

Read

/usr/include/linux/keyboard.h

Read the man pages for showkey, dumpkeys and loadkeys.
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.