Connecting Tech Pros Worldwide Forums | Help | Site Map

KeyPressed function?

Karl Ebener
Guest
 
Posts: n/a
#1: Jul 22 '05
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

Karl Heinz Buchegger
Guest
 
Posts: n/a
#2: Jul 22 '05

re: KeyPressed function?


Karl Ebener wrote:[color=blue]
>
> 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.
>[/color]

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
kbuchegg@gascad.at
Karl Ebener
Guest
 
Posts: n/a
#3: Jul 22 '05

re: KeyPressed function?


Hi![color=blue]
> 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.
>[/color]

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
chris
Guest
 
Posts: n/a
#4: Jul 22 '05

re: KeyPressed function?


Karl Ebener wrote:[color=blue]
> Hi!
>[color=green]
>> 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.
>>[/color]
>
> 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*}
>[/color]
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
Karl Heinz Buchegger
Guest
 
Posts: n/a
#5: Jul 22 '05

re: KeyPressed function?


Karl Ebener wrote:[color=blue]
>
> Hi![color=green]
> > 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.
> >[/color]
>
> Could you give me a hint for Linux systems? I looked but didn't find
> anything....[/color]

Sorry. I donÄt know about Linux. You should ask in a newsgroup dedicated
to Linux programming.
[color=blue]
>
> Another question: Is there a way to make a function return a list?
> e.g.
> int[] abc() { //*returning list*}[/color]

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
kbuchegg@gascad.at
Arijit
Guest
 
Posts: n/a
#6: Jul 22 '05

re: KeyPressed function?


Karl Ebener wrote:[color=blue]
> Hi!
>[color=green]
>> 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.
>>[/color]
>
> Could you give me a hint for Linux systems? I looked but didn't find
> anything....[/color]

You can try the GNU readline library.

-Arijit
Default User
Guest
 
Posts: n/a
#7: Jul 22 '05

re: KeyPressed function?


Karl Ebener wrote:
[color=blue]
> Could you give me a hint for Linux systems? I looked but didn't find
> anything....[/color]

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




Brian
E. Robert Tisdale
Guest
 
Posts: n/a
#8: Jul 22 '05

re: KeyPressed function?


Karl Ebener wrote:[color=blue]
>
> 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.[/color]

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.
Closed Thread