Unix Programming - how to macro define "ctrl+up" key?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > May 2006 > how to macro define "ctrl+up" key?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author how to macro define "ctrl+up" key?
key9

2006-05-21, 7:15 am

Hi all

Q1
I use

printf("%d",mygetch());

to print what I 've got from a keypress's code to display it's int code.

And I found I have no ability macro define some key combination like
"ctrl+up" which print "27 91 53 65"

How to define it?

#DEFINE KEY_CTRL_UP ??? <-- how to write?

is there exist some pre-defined .h file I can reference?

Q2
default , when I print a '\b' char to terminal , It will display a "char" ,
not delete a char before cursor,

how to set struct termios to make that?


Q3
I found I got no knowledge on unix charset/terminal coding , what should I
read next?

thank you
very much

key9


Doug McIntyre

2006-05-21, 1:14 pm

We have to make alot of assumptions here, because you don't give us
alot of information about your environment. It sounds like you are
dealing with a text terminal session on a Unix system. We don't know
which of the 1,000's terminal types capable in a Unix system you are
attempting to use, or what environment beyond that at all, which makes
things generally much more difficult.

"key9" <iamkey9@126.com> writes:
>Q1
> I use
> printf("%d",mygetch());
> to print what I 've got from a keypress's code to display it's int code.


> And I found I have no ability macro define some key combination like
>"ctrl+up" which print "27 91 53 65"


> How to define it?


This depends quite alot of your *console* environment, not your unix
machine, and whatever terminal it decides to emulate. Most likely,
ctrl+up is no different than hitting up. Trying to emulate an ancient
text terminal environment, there is no way to detect if the ctrl key
is held or not, you are only shipped pure ASCII characters. The up key
has no ASCII equivilent, so the ancient terminal people made up escape
sequences that the extra keys did to map into ASCII character
sequences, starting with logically enough the ESC ASCII character.

So, this depends heavily on your terminal emulation and whatever combo
you are using, so its impossible to say. You may want to readup on
some of the terminfo man sections so you can start loading some of the
database that exists on unix trying to deal with these 1000s of
different terminals that could be in use.

>Q2
> default , when I print a '\b' char to terminal , It will display a "char" ,
>not delete a char before cursor,


> how to set struct termios to make that?


Again, its going to be quite a mess figuring it all out, \b is
probably not going to do what you want. But, rather than re-inventing
the wheel, you should investigate a package that already deals with
all that stuff for you, like curses (ncurses). It sounds like this
would probably help you out considerably.


>Q3
> I found I got no knowledge on unix charset/terminal coding , what should I
>read next?


Read up on terminfo and ncurses.



key9

2006-05-21, 7:14 pm

Great thanks.

cursor/ncursor is too big for my app.

what I need is just a very small adapter to terminal to test my idea, but
now I found to goal that , maybe I must have to make a system can boil the
sea.
.......

keep on trying...


Thomas Dickey

2006-05-23, 7:16 am

key9 <iamkey9@126.com> wrote:
> Great thanks.


> cursor/ncursor is too big for my app.


> what I need is just a very small adapter to terminal to test my idea, but
> now I found to goal that , maybe I must have to make a system can boil the
> sea.
> ......


> keep on trying...


it helps to read the recommended documentation
(asking questions on a newsgroup takes more work).

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com